The difference between Hibernate's Save method and SQL insert

Source: Internet
Author: User

public Boolean Adddiscuss (discuss discuss) {
Session session = Hibernatesessionfactory.getsession ();//Get Session Object
try {
Session.save (Discuss);//save information, non-line error,cannot add or update a child row:a FOREIGN KEY constraint fails

} catch (Exception ex) {
Ex.printstacktrace ();
return false;
//}
Hibernatesessionfactory.closesession ();//Close Session Object
return true;
Session session = Hibernatesessionfactory.getsession ();
Query query = session.createsqlquery ("INSERT into discuss values (0,?,?,?,?,?,?)");
Query.setparameter (0, Discuss.gettid ());
Query.setparameter (1, Discuss.getuid ());
Query.setparameter (2, Discuss.getcontent ());
Query.setparameter (3, Discuss.gettime ());
Query.setparameter (4, Discuss.gettheme ());
Query.setparameter (5, Discuss.getname ());
System.out.println (query);
int num=query.executeupdate ();

Hibernatesessionfactory.closesession ();
if (num>0)
return true;
else{
return false;
}
}

The difference between Hibernate's Save method and SQL insert

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.