-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Constraint violation
PostPosted: Thu Jul 19, 2007 8:19 am 
Newbie

Joined: Tue Jul 10, 2007 9:59 am
Posts: 6
Location: Argentina
Hi, is there any way of knowing which object has caused a constraint violation when I execute the save or update methods. I'm executing the save or update methods over an object which has many others and so on.
Thanks!!

Leandro


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:04 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
Check the log of hibernate.
It should contain a clear explanation.

If you haven't done so already - add the following poperty to the main conifguration file of hibernate:

<property name="show_sql">true</property>

To enable sql statements logging.

Vitaliy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:24 am 
Newbie

Joined: Tue Jul 10, 2007 9:59 am
Posts: 6
Location: Argentina
Thanks Vitaliy!

I mean at runtime...
I need to know which object has caused the constraint violation to inform it to the user...
Thanks!!

Leandro


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:26 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
Can't you get this info from the details of the exception?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 10:29 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
It depends on what piece of software checks the constraint.

If it ist Hibernate Validation you should be able to examine the exception in a fairly straight forward way.

If it is the database your options will depend on the database and the actual constraint. E.g. in oracle 8 (I'm not sure about 9) it is not possible to tell from the exception which field was to long during a insert. In Oracle 10 you will get the column name in the exception, but the exact position is probably Language dependent. For real constraints (foreign key, check constraints, Unique constraitns) you will get the name of the constraint somewhere in the message and could examine the data dictionary for more information

Jens


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 1:24 pm 
Newbie

Joined: Tue Jul 10, 2007 9:59 am
Posts: 6
Location: Argentina
Thanks Jens!
I'm working with Oracle 10 and I think that the database is checking the constraints, how can I verify this?

I need to know which object has caused the constraint violation to inform it to the user...

schauder wrote:
For real constraints (foreign key, check constraints, Unique constraitns) you will get the name of the constraint somewhere in the message and could examine the data dictionary for more information

I'm using real constraints, but when you say data dictionary, what do you mean?

Thanks!!

Leandro


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 2:08 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Hi again,
You can very easily determine if a error message comes from Oracle: If so it will contain Errorcodes of the form
ORA-#####

where ##### stands for some number

If you are updating/inserting more then one object in one go you don't have much chances to relyable identify the object which caused the problem. In fact it might not even be well defined.

If you are inserting/updating a single row per transaction I guess you could store the executed sql statement, and the bind variables and thereby identifying the object. At least I think this should be possible with an 'intercepter'(?), a object that gets informed whenever a sql statement is executed.

HTH
Jens


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 8:43 am 
Newbie

Joined: Tue Jul 10, 2007 9:59 am
Posts: 6
Location: Argentina
Ok, thanks Jens!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.