-->
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.  [ 4 posts ] 
Author Message
 Post subject: Empty Embebbed marked as dirty
PostPosted: Wed Jul 09, 2008 2:46 pm 
Newbie

Joined: Wed Jul 09, 2008 2:26 pm
Posts: 3
Hi,
Seems like Hibernate does not properly handle empty Embedded (embedded with all properties set to null). Every time we read from the database the object with null Embedded, it gets marked as dirty because our Entity creates instance of the Embedded but not making any assignments to its properties. That translates into database update after each read.

That’s what the doc says on component mapping (embedded)
http://www.hibernate.org/hib_docs/v3/re ... components
Quote:
The null value semantics of a component are ad hoc. When reloading the containing object, Hibernate will assume that if all component columns are null, then the entire component is null. This should be okay for most purposes.


Which means that embedded objects with no assigned properties will be rehydrated as null on next fetch, which is logical as there is nothing in the database that indicates that object was ever assigned.

But here’s the code from ComponentType (hibernate mapping for embedded). Before flush session traverses through all columns and checks if they were changed by calling isEqual with old and new value.
If any of the object, old or new, is null, it automatically assumes unequalness and marks it as dirty, when in fact it should have also checked all contained properties and if all of them are null, treat the Embedded as null too, as semantically Embedded with all null properties IS equivalent to null.


Code:
public boolean isEqual(Object x, Object y, EntityMode entityMode)
         throws HibernateException {
      if ( x == y ) {
         return true;
      }
      if ( x == null || y == null ) {
         return false;
      }
      Object[] xvalues = getPropertyValues( x, entityMode );
      Object[] yvalues = getPropertyValues( y, entityMode );
      for ( int i = 0; i < propertySpan; i++ ) {
         if ( !propertyTypes[i].isEqual( xvalues[i], yvalues[i], entityMode ) ) {
            return false;
         }
      }
      return true;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 3:33 pm 
Newbie

Joined: Wed Jul 09, 2008 2:26 pm
Posts: 3
Certainly implementation bug. Any chance for Hibernate team to include check for nullness of all Embedded properties, sort of deep isNull method?
Something similar to this
Code:

public boolean isEqual(Object x, Object y, EntityMode entityMode)
         throws HibernateException {
      if (( x == y ) || (isNull(x) && isNull(y))
      {
         return true;
      }
      if ( x == null || y == null ) {
         return false;
      }
      Object[] xvalues = getPropertyValues( x, entityMode );
      Object[] yvalues = getPropertyValues( y, entityMode );
      for ( int i = 0; i < propertySpan; i++ ) {
         if ( !propertyTypes[i].isEqual( xvalues[i], yvalues[i], entityMode ) ) {
            return false;
         }
      }
      return true;
}

/**
* Deep check for nullness.
*
*/
private boolean isNull(Object obj, EntityMode entityMode) throws HibernateException {
    boolean result = (obj == null);
   
    if (!result) {
        Object[] values = getPropertyValues(obj, entityMode);
        for (int i = 0; i < values; i++ ) {
           if (values[i] != null) {
               result = false;
               break;
           }
         }
    }
    return result;
}


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 3:40 pm 
Newbie

Joined: Wed Jul 09, 2008 2:26 pm
Posts: 3
Any thoughts, comments?

Thanks


Top
 Profile  
 
 Post subject: Re: Empty Embebbed marked as dirty
PostPosted: Thu Jan 08, 2015 10:00 am 
Newbie

Joined: Mon Mar 13, 2006 2:03 pm
Posts: 3
Hi,
Did anyone ever find a resolution to this issue?
I also am experiencing this issue and would love to know how to resolve it.
Mike


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