-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hib.-Validator won't validate "new" (=transient) B
PostPosted: Tue Mar 28, 2006 4:14 pm 
Newbie

Joined: Tue Mar 28, 2006 4:03 pm
Posts: 11
Hi all,

opposed to this


http://forum.hibernate.org/viewtopic.php?t=955446

it seems like there is a problem validating beans that have never been attached to the session/EntityManager.

when i do

Code:
ClassValidator cv = new ClassValidator(MyBean.class);
cv.getInvalidValues(aReallyNewAndTransientBeanInstance)


the validator will NOT complain about an invalid bean. (Altough everything works as expected when i try to persist this bean or when i check a detached bean.)

I traced into ClassValidator to see whats happening and i found this code:

Code:
for ( int i = 0; i < memberValidators.size() ; i++ ) {
         Member getter = memberGetters.get( i );
         if ( Hibernate.isPropertyInitialized(bean, getter.getName() ) ) {
            Object value = getMemberValue( bean, getter );
            Validator validator = memberValidators.get( i );
            if ( !validator.isValid( value ) ) {
               String propertyName = getPropertyName( getter );
               results.add( new InvalidValue( messages.get( validator ), beanClass, propertyName, value, bean
) );
            }
         }
      }   


The thing ist that


Quote:
Hibernate.isPropertyInitialized(...)



returns false for a "new" (transient) bean, and so all my member/property constraints do NOT get checked....


Is this a bug or is there a way to "initialize" a transient bean for use with the validator? ( I tried Hibernate.initalize(...) also, but result was the same...)


My Versions:

* JBoss 4.0.4RC1
* Hibernate Annotations 3.1beta8
* Hibernate EntityManager 3.1beta6


Rgds,

M.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 3:18 pm 
Newbie

Joined: Tue Mar 28, 2006 4:03 pm
Posts: 11
well, further investigations revealed that this just happens for classes that have been "enhanced" with CGLIB.

It seems like the problematic code is the line

Code:
return fieldInterceptor != null && fieldInterceptor.isInitialized( propertyName );


in [Hibernate.java]:

Code:



   public static boolean isPropertyInitialized(Object proxy, String propertyName) {
      
      Object entity;
      if ( proxy instanceof HibernateProxy ) {
         LazyInitializer li = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer();
         if ( li.isUninitialized() ) {
            return false;
         }
         else {
            entity = li.getImplementation();
         }
      }
      else {
         entity = proxy;
      }
      
      if ( entity instanceof InterceptFieldEnabled ) {
         FieldInterceptor fieldInterceptor = FieldInterceptor.getFieldInterceptor(entity);
         return fieldInterceptor != null && fieldInterceptor.isInitialized( propertyName );
      }
      else {
         return true;
      }
      
   }



if this would be changed to

Code:
         return fieldInterceptor == null || fieldInterceptor.isInitialized( propertyName );


everything would be fine!?

Any chance of having this "patch" applied to svn?[/code][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 4:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
open a JIRA issue please and assign it to me

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 01, 2006 4:21 pm 
Newbie

Joined: Tue Mar 28, 2006 4:03 pm
Posts: 11
done.

http://opensource.atlassian.com/projects/hibernate/browse/ANN-301

just i don't know how to assign this issue to you, maybe i don't have sufficient rights in jira...

(and sorry for the crosspost in jboss forum)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 6:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is fixed

_________________
Emmanuel


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