-->
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: @Embedded returns null - can this be overridden?
PostPosted: Wed Aug 16, 2006 7:44 pm 
Newbie

Joined: Wed Aug 16, 2006 7:30 pm
Posts: 7
Currently if an Embeddable objects fields are all null, when the object is retrieved from the database the object is returned as null.

Is there any configuration option/annotation that can be used to return an object that's fields are all null?

ie. this would allow field checking without having to use many extra null checks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 4:42 pm 
Beginner
Beginner

Joined: Wed Apr 26, 2006 2:41 pm
Posts: 30
what prevents you from assigning the parameter in Java:

Code:
private embedded =  new EmbeddedObject()


You can do this in the constructor and unless Hibernate sets the variable with a new object you will get that one.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 4:45 pm 
Beginner
Beginner

Joined: Wed Apr 26, 2006 2:41 pm
Posts: 30
... or does hibernate then explicitly set that to be null? I didn't think that was the case but I now realize that all of my embedded objects are not null in the db.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 5:26 pm 
Newbie

Joined: Wed Aug 16, 2006 7:30 pm
Posts: 7
In the case I'm dealing with EmbeddedObject() would have something like 2 fields that are Strings like firstName lastName.

and if you create the object.. like

embedThis = new EmbeddedObject() and then persist it without any of embedThis's fields being set.. it's set to null.

So unless we did a hack like making a base class that contained an int and inherited all Embeddables from it (uglllly hack) we end up with null embedded objects.

you can have an object and Hibernate won't care...
If all the embedded objects fields are null, when Hibernate persists it, the object is persisted as null, not as an empty object.

So when it's retrieved you end up with embedThis = null, not an object with no data like you'd expect/want.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 6:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
define a user type @Type

_________________
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.