Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate is driving me crazy !

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • 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.
 
Ranch Hand
Posts: 49
  • 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
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • 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
Posts: 3479
Mac Objective C Clojure
  • 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
Posts: 3479
Mac Objective C Clojure
  • 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.
 
Greenhorn
Posts: 2
  • 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
Posts: 3479
Mac Objective C Clojure
  • 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
Boost this thread!