-->
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: Component set to null if all component columns are null
PostPosted: Sat Nov 11, 2006 2:48 am 
Newbie

Joined: Sat Nov 11, 2006 2:14 am
Posts: 2
(Originally posted to NHibernate by mistake, reposted here)

n the Hibernate documentation, in the Component Mapping section it states that:
Quote:
When reloading the containing object, Hibernate will assume that if all component columns are null, then the entire component is null.


Our code assumes that component values are never null. If components are assigned null values, this causes errors in a lot of places. Adjusting all code to trap and handle null component cases is not really desirable.

Currently the best workaround appears to be as described in http://forum.hibernate.org/viewtopic.php?t=956508 ie to change the "getter" method for the component to create+return a new component object in the case where the component is currently null. This is a nasty hack however, and further causes problems as Hibernate then thinks that the object values have changed and will persist the object every time.

For now, I have locally adjusted the Hibernate code so that components are always initialised even if all component values are null. The code change is very simple, changing the final line of code in org.hibernate.type.ComponentType.hydrate(..) (previous code commented out):

Code:
      // Always return the composite object, even if all values are null
      return values;
      //return notNull ? values : null;
   }


Ideally, it should be possible to switch Hibernate's functionality so that we can choose between the two options (ie whether to set the component to null/not if all component columns are null) - either globally or per-component.

If one of the Hibernate development leads agreed with the change and gave me some pointers, I'd be happy to help with implementation/testing.

regards,
Ste


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 1:04 pm 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hi,

We are running into the same problem. This is very annoying behavior!

Hibernate team? Anyone?

Thanks!
Michael.


Top
 Profile  
 
 Post subject: Re: Component set to null if all component columns are null
PostPosted: Thu Nov 04, 2010 4:00 pm 
Newbie

Joined: Thu Nov 04, 2010 3:57 pm
Posts: 1
The easy solution is below. If you want to know more details about how to intercept and change the object, please visit.

http://bit.ly/acZJBb

Let's say the component you are talking about is an Address.

protected Address _address;virtual public Address Address
{

get { return _address ?? (_address = new Address()); }

set { _address = value; }
}


Top
 Profile  
 
 Post subject: Re: Component set to null if all component columns are null
PostPosted: Fri Jun 13, 2014 11:52 am 
Newbie

Joined: Fri Jun 13, 2014 11:45 am
Posts: 1
BUMP!

Is there any elegant way to solve this problem?


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.