-->
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.  [ 2 posts ] 
Author Message
 Post subject: Validation and EJB3 dependency injection
PostPosted: Mon Sep 06, 2010 9:46 am 
Newbie

Joined: Thu Mar 27, 2008 12:07 pm
Posts: 3
Hello,

In some custom validations I want to be able to access a database. The Validator.validate() is called from an EJB3 that as a EntityManager field that is injected with @PersistenceContext. How can I pass the instance of the entity manager to the validators? Is there a dependency injection mechanism that I can use?

Br,
Miguel


Top
 Profile  
 
 Post subject: Re: Validation and EJB3 dependency injection
PostPosted: Tue Sep 07, 2010 4:13 am 
Hibernate Team
Hibernate Team

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

the path to a solution goes via a custom ConstraintValidatorFactory. This is discussed here - AccessingtheHibernateSessionwithinaConstraintValidator.
Using a custom factory you should be able to implement your own injection of say the entity manager. However, understand the implications of such an approach, since you are opening yourself up for potential phantom reads.

--Hardy


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