This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi guys. I'm using WebWork and Hibernate3.2 and MySQL4.X I have a register form. When filling the form and press submit, I got the following exception : Duplicate key or integrity constraint violation, Yes, I know what you are thinking, I'm dublicating a unique key. No Sir, I'm not. After a couple of tries, it saved the form ! Trying again to register another user, I got the exception.
Duplicate key or integrity constraint violation, Yes, I know what you are thinking, I'm dublicating a unique key. No Sir, I'm not.
Unfortunately, you are. Exceptions like this are SQLExceptions which just report what the database error tells JDBC, Hibernate does not try to enforce any database constraints. If you can tell us a little more about what you are doing, perhaps someone can spot where you are going wrong.
Here are a few reasons why you might get such an exception.
1. Your mapping is off just a bit, like there is a bi-directional mapping which doesn't have an inverser. Maybe the wrong generated type for the <id> field.
2. You are trying to add a detached object to a Session object that already has that object in the persistence context, and did mot merge the detached object but tried to save() it instead directly.
Can you post your mapping for this object and its related objects, and the code for saving of the object.
The database schema for the database is generated by Hibernate
The relationship between User and CreditCard is one-to-one. The exception seems to origin from a duplicate value of email field of user_table. No, I'm not entering a duplicate value. user_table has only one row and I put logging statements to log each value I enter.
The first time I fill the form, I got an exception from WebWork. The second time, every thing is perfect. Trying to add a new user after that, I always got the duplicate value exception. I'm really tired, I have been trying to solve this for the last 48 hours.
tom collin
Greenhorn
Joined: Oct 26, 2006
Posts: 2
posted
0
I want to collect more information about your Exceptions so that I may recognise the problem which you have. Can you post the detail of your Exceptions? You could copy the Exceptions in here!
I solve it ! Hibernate is not guilty, it is my stubidity :roll: To integerate WebWork with Spring, you have to declare action instances as singleton. Well, I was not doing so. So, every time the action executed, there is a User object and it will ask the facade to try to save it to the database again. Sorry Hibernate. And hearty thanks for you all.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.