session.get()/load()的参数使用问题!

在做课设keshe的时候:由于定义主键id是int类型的,所以在用session.load/get()方法是就会出错。用session.createCriteria().add(Restriction.eq("",id))

 

hibernate的官方文档里有个例子:

Cat cat = session1.get(Cat.class, catId);

Cat cat = (Cat) firstSession.load(Cat.class, catID);

catID指对象标识符。二个catID意思是一样的.

catID 不能是long,int 型的,必须是 Long, Integer型的。

By the way, catID can not be long, int,  it must be Long, Integer, which implements serializable interface. So if your class id is long or int, you have to use Cat cat = (Cat) firstSession.load(Cat.class, new Integer(myCatID); here myCatID is int type.

 

你可能感兴趣的:(session.get()/load()的参数使用问题!)