• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.BatchUpdateException: Duplicate entry

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK this exception should speak for itself but.....

I'm using struts2 and hibernate together.
I've got in my JSP an iterator that calls the get method that returns a Set.

Before the Set is being returned I've tested what is in the Set and there are what I expect a unique set.
I don't even understand what is forcing the update. All the action is meant to do is display a Set of data from the database.

Any ideas??



 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kris Reid wrote:
I don't even understand what is forcing the update. All the action is meant to do is display a Set of data from the database.

So, you are not even expecting an update to happen when it is updating..

Are you trying to load the entities from a session where you have other entities already added or updated?

Could you post your code?

It could be because of the following.
I think, in a session, if you try to do a load some entities from the database, if some of those entities are already changed in your same session, hibernate will first do a flush and then load the entities.

This is to make sure that it gets the latest entities..
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I'm using struts there are two methods

The first is the action which determines which set to get



And then the one called from the JSP to display the results of that set.
The println is just there to show me that the right stuff is in the set




Both println print the same set. Which is what is in the database

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this update is being called explicitly how can I find out what is making it fire?
I have several actions just like this. They all look the same but this is the only one doing a update

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must be doing this inside some Hibernate session and inside a transaction.
Where are the transaction boundaries.
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4 hours later here is lesson to keep damn logic out of JSP






 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
glad you figured out...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic