2013年9月9日星期一

Hibernate in session.load () method error

Session session = sessionFactory.openSession();		
Transaction transation = session.beginTransaction();
//获取需要修改的用户
Employee emp = (Employee)session.load(Employee.class, 2);


If I only write directly int type , will complain , but if you change the type Integer instance can the code below

Session session = sessionFactory.openSession();		
Transaction transation = session.beginTransaction();
//获取需要修改的用户
Employee emp = (Employee)session.load(Employee.class, new Integer(2));


Why is there such a situation ? You can not do auto-unboxing boxing ? I use the jdk is 1.7
------ Solution -------------------------------- ------------
the exception stickers chant

------ Solution ------------------------------------ --------
program is not directly in the eclipse shows a syntax error , it means automatic entry box is ok .
but specific to hibernate in the operation , that depends on your version of itself referenced hibernate support auto dismantling it.
should be your hibernate itself does not allow to do this, so you just have to write the type of object to be queried , and this has nothing to do with jdk
------ Solution ------- -------------------------------------
use int tried it, easy to use.
LZ finally the exception stickers
------ Solution ------------------------------ --------------


If a syntax error is really the case, make sure that the eclipse window-> Preferences-> java-> Compiler, inside the Compiler compliance level is not selected, the corresponding version of your JDK compiler. JDK7 I have not used , but I want you to choose one which is at least 1.5 , in order to ensure automatic disassembly is correct.
You try
------ Solution -------------------------------- ------------
LZ of the JDK does not support automatic entry box
------ Solution ---------------- ----------------------------
course, to use the Integer . .
------ For reference only -------------------------------------- -
exceptions are as follows:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method load (Class, Serializable) in the type Session is not applicable for the arguments (Class, int)

at com.liang.view.TestMain.updateEmployee (TestMain.java: 43)
at com.liang.view.TestMain.main (TestMain.java: 20)
------ For reference only ---------------- -----------------------


program is a syntax error in the package being given a load that
My Hibernate is 3.3 version of
------ For reference only --------------------------- ------------
and I use the same Hibernate jar package into roughly the same project , the direct use of type int is no problem
------ For reference only ---------------------------------------

how could I the jak is a relatively new version , jdk-7u1-windows-i586
------ For reference only ---------------------- -----------------
[Quote = reference 7th floor of replies: ]

Ha ha ha ! ! Thank leftstick reminder ! Originally this project uses JDK 1.3 , there is no use my JDK, I changed my version of the JDK , will be able automatic packing unpacking , the problem is finally solved ! Thank you

------ For reference only ---------------------------------- -----

not , JDK1.5 after auto dismantling, my other projects can directly use an int type
------ For reference only ----- ----------------------------------
I am also the same problem, seemingly only with Integer Package that could be used

没有评论:

发表评论