-->
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: Accessing the Hibernate Session within a ConstraintValidator
PostPosted: Mon Jul 11, 2011 10:36 am 
Newbie

Joined: Tue Jul 05, 2011 10:03 am
Posts: 5
I tried to implement example from http://community.jboss.org/wiki/AccessingtheHibernateSessionwithinaConstraintValidator

In example we need to create custom ConstraintValidatorFactory. According to example, our custom ConstraintValidatorFactory has to extend ConstraintValidatorFactoryImpl. And in getInstance() method it calls parent method: super.getInstance(key).

But in hibernate validator 4.2.0.Final(which I use) this method (getInstance of ConstraintValidatorFactoryImpl) is final. That's why I can't override method getInstance(). What I should do?

Thank you.


Top
 Profile  
 
 Post subject: Re: Accessing the Hibernate Session within a ConstraintValidator
PostPosted: Tue Jul 12, 2011 4:09 am 
Newbie

Joined: Tue Jul 05, 2011 10:03 am
Posts: 5
And I discoveered, that deprecated method "connection()" of org.hibernate.Session is used.

I think, that this example is outdated. Can anybody give actual example, how to access Hibernate Session within a ConstraintValidator? Or how to realize @Unique constraint?


Top
 Profile  
 
 Post subject: Re: Accessing the Hibernate Session within a ConstraintValidator
PostPosted: Tue Jul 12, 2011 5:02 am 
Hibernate Team
Hibernate Team

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

right ConstraintValidatorFactoryImpl is not final, but if you look at the actual code getInstance does not much:
Code:
   public final <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
      return ReflectionHelper.newInstance( key, "ConstraintValidator" );
   }

Just implement ConstraintValidatorFactory directly.

Regarding connection(), this call is indeed deprecated (for a long time in fact). However, there is no real alternative atm. So the connection part still holds, only the factory code needs to be adjusted. Feel free to leave a comment on the wiki.

--Hardy


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.