Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can deletion trigger unique constraint violation? Hibernate 2

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the following sql ran on the db (oracle):
alter table abc add constraint c_abc unique(abc1,abc2,abc3).
On deletion I get :
net.sf.hibernate.exception.ConstraintViolationException: could not update "abc hibernate class name"...
.......
Caused by: java.sql.SQLException: ORA-00001: unique constraint (DBNAME.c_abc) violated
......
How can this happen in deletion?

Thank you,
John.

PS
On insertion it allows me to crate a two records with the same value in abc2 but different case. But it does not allow to delete it.
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Turn on SQL-output and have a look if you are really performing a DELETE. Do you have a db trigger which intercepts the DELETE and replaces it with an UPDATE?
 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you for your answer. I am not looking for trivial answers though.
I am permitted to delete and obviously I do not have any triggers.
Any other ideas?

Thanks.
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it obvious that you do not have any triggers? Can you show us the generated sql-queries? What are you doing when the error shows up? Do you want to replace an existing row by another one by delete the old and insert the new one? If you do so, try if it works if you call flush() (if that existed in Hibernate2) between delete and insert.
 
Gene Hilpert
Ranch Hand
Posts: 51
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian is right you need to see the SQL.
You should not get a ORA-00001 error on a delete so it is doing something your not expecting, and the SQL will show your that.
Could you be deleting a record than inserting a recond with the key you just deleted? If the delete is failing you could get the error.


PS in Oracle ABC2 does not equal abc2 it is case sentitive. But are you messing up on the case when tring to delete it? This could also be part of the problem above.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic