aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate is driving me crazy ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate is driving me crazy !" Watch "Hibernate is driving me crazy !" New topic
Author

Hibernate is driving me crazy !

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
hi,

Can You breif tell more about the Excepiton in hibrnate so that we can recognise that issues
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

BillingDetails.hbm.xml

User.hbm.xml

WebWork execute( ) method :

GeneralFacade Spring bean:

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
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!
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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://aspose.com/file-tools
 
subject: Hibernate is driving me crazy !