-->
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: Null value semantics of composite elements
PostPosted: Wed Apr 20, 2005 11:39 am 
Newbie

Joined: Wed Apr 20, 2005 11:22 am
Posts: 4
Hi,

I'm using Hibernate version 2.1.6. The documentation specifies that a composite element is set to null if all its properties are null.

Is it possible to change the null value semantics so that a composite element with all null properties is initialised with a default constructed object with all its fields uninitialised/set to null instead?

If I've missed documentation relating to this I apologize and would be grateful for a pointer. I've searched for information about this in the documentation, FAQ, Forums and on Google.

Very grateful for your response,

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 8:46 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
If you really think of it the current behavior makes sense.

Composite elements that have all null properties in the database represent an instance of 'null'. It wouldn't make sense to initialize a default constructed instance.

The 'instance' is null in the relational world, so the reference should be null when it is reconstituted in the object world.

Now, you commented that it would be nice to initialize an object with all its properties made null. That is pretty dangerous to do isnt it? Hibernate uses reflection to instantiate objects using the default no-arg constructor. Those instantiated objects have default instantiation behavior whic probably means not all its fields are null. Then , Hibernate would have to go throug all the mapped properties and null them. Depending on how the class was written, this could put the class in a dangerous state exposing it NullPointerExceptions, etc..

Just some thoughts....


Joe

_________________
Joe W


Top
 Profile  
 
 Post subject: It makes sense in our object model
PostPosted: Thu Apr 21, 2005 5:45 am 
Newbie

Joined: Wed Apr 20, 2005 11:22 am
Posts: 4
jw3525 wrote:
If you really think of it the current behavior makes sense.


It makes sense in some cases. In my case it's not a useful behaviour. As the Hibernate documentation says, null value semantics are ad-hoc. Hibernate has picked one implementation, and it happens to not work for us in the current situation. Our object model is such that we wish that particular composite element to always be initialised. It's not important whether its properties are set to null or left uninitialised, what's important is that the composite element is not null. This is the appropriate behaviour in our object model, and I'm asking for a way to implement this in Hibernate.

How hard would it be to write a UserType that extends the current composite element type and overrides this behaviour? Would that be possible?


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.