Hibernate is reported java.lang.NullPointerException for the commit method.

Source: Internet
Author: User

1  Public intupdateemp (emp emp) {2 Transaction TX;3Session session =sft.getsessionfafactory (). Opensession ();4         Try {5             //The thing that opens the session must be placed in a thing object in order to do the following or to report a null pointer exception6tx=session.begintransaction ();7 session.update (EMP);8 tx.commit ();9             return1;Ten}Catch(hibernateexception e) { One Tx.rollback (); A e.printstacktrace (); -             return0; -}finally{ the sft.closesession (); -}

Can also be written like this

1  Public intaddemp (emp emp) {2Session session =sft.getsessionfafactory (). Opensession ();3         Try {4 session.begintransaction ();5 Session.save (EMP);6             //tx.commit ();7 session.gettransaction (). commit ();8             return1;9}Catch(hibernateexception e) {Ten session.gettransaction (). rollback (); One e.printstacktrace (); A             return0; -}finally{ - sft.closesession (); the}

2 object references an unsaved transient instance
Modify Cascade= "Save-update"

1 class= "Cn.entity.Dept" lazy= "false" cascade= "Save-update" 2  column= "Dno"/> 3  4  5  6  7  8  <set name= "Emps" lazy= "false" cascade= "Save-update" >
<key column= "Dno"/>
<one-to-many class= "Cn.entity.Emp"/>
</set>

3Cannot forward after response have been committed

Hibernate is reported java.lang.NullPointerException for the commit method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.