SSH + ORACLE: org. hibernate. Exception. constraintviolationexception: cocould not execute JDBC batch UPDA

Source: Internet
Author: User

During SSH integrated development, it took nearly one day to solve a problem.

First, the page reports the following error:

Org. hibernate. Exception. constraintviolationexception: cocould not execute JDBC batch update

 

On the console, the following error occurs:

Java. lang. illegalstateexception <br/> at Org. apache. catalina. connector. responsefacade. senderror (responsefacade. java: 407) <br/> at Org. apache. struts2.dispatcher. dispatcher. senderror (dispatcher. java: 752) <br/> at Org. apache. struts2.dispatcher. dispatcher. serviceaction (dispatcher. java: 505) <br/> at org.apache.struts2.dispatcher.ng.executeoperations.exe cuteaction (executeoperations. java: 77) <br/> at Org. apache. struts2.dispatcher. ng. filter. strutsprepareandexecutefilter. dofilter (strutsprepareandexecutefilter. java: 91) <br/> at Org. apache. catalina. core. applicationfilterchain. internaldofilter (applicationfilterchain. java: 235) <br/> at Org. apache. catalina. core. applicationfilterchain. dofilter (applicationfilterchain. java: 206) <br/> at Org. apache. catalina. core. standardwrappervalve. invoke (standardwrappervalve. java: 233) <br/> at Org. apache. catalina. core. standardcontextvalve. invoke (standardcontextvalve. java: 191) <br/> at Org. apache. catalina. core. standardhostvalve. invoke (standardhostvalve. java: 127) <br/> at Org. apache. catalina. valves. errorreportvalve. invoke (errorreportvalve. java: 102) <br/> at Org. apache. catalina. core. standardenginevalve. invoke (standardenginevalve. java: 109) <br/> at Org. apache. catalina. connector. coyoteadapter. service (coyoteadapter. java: 298) <br/> at Org. apache. coyote. http11.http11processor. process (http11processor. java: 852) <br/> at Org. apache. coyote. http11.http11protocol $ http11connectionhandler. process (http11protocol. java: 588) <br/> at org.apache.tomcat.util.net. jioendpoint $ worker. run (jioendpoint. java: 489) <br/> at java. lang. thread. run (unknown source) 

 

1. for errors on the page

Cause: the association relationship is set in the database table, but the association relationship is not set during data insertion. An error is reported during data insertion.
Correct: Set the relationship between tables.

 

2. Console errors

An error occurs. We generally look at the console, but this error has nothing to do with the real error. For the specific reason, Google or Baidu.

 

A table in the database adopts the form of a joint primary key. One of the keys is a foreign key.

 

The specific cause is still Error 1. When designing ORACLE data, we set trigger and sequence for the automatic ID. However, for hibernate, a sequence will run to generate an ID before inserting data. Therefore, if there is a trigger, a sequence will be run again, so we will find that the ID is increased in step 2. Delete the trigger and the step is 1.

 

The primary key Configuration Policy of the object class is as follows:

<ID name = "ID" type = "Java. lang. integer "> <br/> <column name =" ID "/> <br/> <generator class =" sequence "> <br/> <Param name =" sequence "> temp_vehicle_data_seqs </param> <br/> </generator> <br/> </ID>

 

The following is the hibernate processing code:

 Gethibernatetemplate (). setflushmode (0); <br/> gethibernatetemplate(cmd.exe cute (New hibernatecallback () {<br/> Public object doinhibernate (session) <br/> throws hibernateexception, sqlexception {<br/> session. connection (). setautocommit (false); <br/> set <tempmtitem> tempmtitem = List. get (0 ). gettempmtitems (); <br/> for (tempmtitem MT: tempmtitem) {<br/> session. save (MT); <br/> for (Object LAN: MT. gettempmtitemlanguages () {<br/> tempmtitemlanguage templan = (tempmtitemlanguage) LAN; <br/> created id = new tempmtitemlanguageid (); <br/> ID. setitemid (MT. GETID (); <br/> ID. setlngcde (templan. getlanguage (); <br/> templan. setid (ID); <br/> session. save (templan); <br/>}< br/> for (tempvehicledata temp: List) <br/> session. save (temp); <br/> session. flush (); <br/> session. connection (). commit (); <br/> return NULL; <br/>}< br/>}); <br/> gethibernatetemplate (). setflushmode (1 );

When the session. Save () or gethibernatetemplate (). Save () method is called, the ID set to the object based on sequence is automatically generated.
 

Links to several articles:

Http://www.blogjava.net/caixuetao/archive/2007/04/26/113433.html

Http://www.cnblogs.com/xuwenyan/archive/2008/02/18/1072795.html

Http://www.cppblog.com/jerryma/archive/2010/03/10/109334.aspx

Http://coldandhot.blog.hexun.com/11958153_d.html

 

 

 

Related Article

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.