-->
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: Validator: Class-level constraint that acesses EntityManager
PostPosted: Fri Mar 12, 2010 9:53 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Hi guys
I am trying to implement a unique constraint validator, one that checks that no entities exist in the database before passing validation. This validator class implements ConstraintValidator. We are using JPA2 and EJB 3.1, and need access to either the EntityManager or the EJB's. But no matter how I try to inject either of them, I always get null (i.e. it is not injected). I have also tried accessing the EntityManager using:

Persistence.createEntityManagerFactory("myPU")

But this throws an exception:

"The chosen transaction strategy requires access to the JTA TransactionManager".

We are using Hibernate Entitymanager 3.5.0-CR-2 and the Hibernate Validator that is bundled with Glassfish V3.

Any suggestions on how to accomplish this would be greatly appreciated.

Regards,

Anders


Top
 Profile  
 
 Post subject: Re: Validator: Class-level constraint that acesses EntityManager
PostPosted: Tue Mar 23, 2010 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I think this might help - How to write a custom ConstraintValidatorFactory.

Also have a look at viewtopic.php?f=9&t=999868

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Class-level constraint that acesses EntityManager
PostPosted: Fri Mar 26, 2010 3:31 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Great! Looks like exactly what I need, thanks.

-Anders


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.