This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate is driving me crazy !

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
saranga rao
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Can You breif tell more about the Excepiton in hibrnate so that we can recognise that issues
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic