您的位置:首页 > 移动开发

The method load(Class, Serializable) in the type Session is not applicable for the arguments (Class<

2015-02-27 16:59 603 查看
Transaction transaction = session.beginTransaction();

//load是通过主键属性,获取对象的实例

Employee employee =(Employee) session.load(Employee.class, 1);

employee.setName("demo");

transaction.commit();

session.close();

报错The method load(Class, Serializable) in the type Session is not applicable for the arguments (Class<T>, int)

myeclipse明显的报错,这说明在myeclipse中jdk的自动拆装箱没有自动完成,但我的jdk用的是java8的。

使用

Transaction transaction = session.beginTransaction();

//load是通过主键属性,获取对象的实例

Employee employee =(Employee) session.load(Employee.class, new Integer(1));

employee.setName("demo");

transaction.commit();

session.close();

就行了,网上找了下,发现这应该是hibernate版本的问题,在hibernate中的操作,要看你引用的hibernate版本本身是否支持自动拆装。

应该是hibernate本身不允许这么做,所以才必须要写成对象类型才能进行查询,这和jdk已经无关了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐