-->
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.  [ 3 posts ] 
Author Message
 Post subject: ConstraintViolationException or EntityExistsException?
PostPosted: Thu Aug 23, 2007 7:53 am 
Newbie

Joined: Thu Aug 23, 2007 7:38 am
Posts: 2
Hello!

I am using Hibernate Annotations 3.3.0 GA and Hibernate Core 3.2.5.GA with a MySQL 5 database.
One of my object attributes is annotated with

@Column(nullable = false, unique = true)
public String getPath() { ... }

and the MySQL table definition accordingly says

UNIQUE KEY `path` (`path`)

When I try to persist an object with an existing value for 'path' I get a ConstraintViolation, which is the correct and expected behavior.
I wonder, however, why I get a org.hibernate.exception.ConstraintViolationException instead of a javax.persistence.EntityExistsException.

My application consistently uses the EJB3 persistence API and no Hibernate-specific API calls. Why is a Hibernate exception thrown in an EJB3-only environment?

Thank you and best regards, Uwe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 9:31 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
The exception is thrown because Hibernate is your EJB3 persistence provider. These are Runtime Exceptions so they dont have to be declared. The above behaviour is absolutely fine in my opinion.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 10:59 am 
Newbie

Joined: Thu Aug 23, 2007 7:38 am
Posts: 2
So how can I detect a constraint violation when using Hibernate's EJB3 implementation without having to use Hibernate-specific classes, i.e. without catching Hibernate-specific exceptions?
In other words, how can I detect a constraint violation without using any vendor-specific code but only plain EJB3-compatible code?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.