Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not execute JDBC batch update

 
vidya archana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When I try to add a record, this is the exception I am getting.

I am using Hibernate and struts

"net.sf.hibernate.JDBCException: Could not execute JDBC batch update"

Anyone pls help to find out the reason a solution to correct it

Thanks

Vidya
 
Dave Salter
Ranch Hand
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend setting Hibernate to show the SQL that is is producing. This may give you an idea what is going wrong.
 
vidya archana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of insertion do I need to generate the query, I am using the save() function given by the Session Class. Also the values in the object are coming correctly also.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vidya archana:
In the case of insertion do I need to generate the query, I am using the save() function given by the Session Class. Also the values in the object are coming correctly also.

No, you don't need to generate any SQL, but Hibernate does. Set Hibernate to show the SQL it is producing as Dave recommends and you will have an easier job figuring out what is wrong.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"net.sf.hibernate.JDBCException: Could not execute JDBC batch update"


This message is really generic and just says that the update failed. You need to determine the root cause.

The exception probably had another exception nested inside of it. The nested exception would print a message and stack trace right below the outer one and would indicate the cause of the exception.

You could have several levels of nested exceptions, but if you scan to the bottom of the list you will see the root cause exception. What does it say?
 
Ashok Pokharkar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem you faced is being displayed as top level message.

Like :
Inserting Record
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
Could not execute JDBC batch updateDONE... !! END.

This problem is due to constraint violation. You are trying to save recoed which might be violating the constraints like Primary Key in existing records.

 
Mathew Lee
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You might need to increment the setId value to next or greater value like
contact.setId(11);
 
Shahir Deo
Ranch Hand
Posts: 80
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Annotations Use @GeneratedValue

with strategy=GenerationType.AUTO
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic