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.  [ 7 posts ] 
Author Message
 Post subject: How to get the null element back?
PostPosted: Tue Jun 20, 2006 3:22 am 
Newbie

Joined: Tue Jun 20, 2006 3:09 am
Posts: 4
I can put a null element into a set and it is successfully persisted into the database. But after I retrieve it back, the null element is gone.


How to get the null element back?


Hers is the map file( the set contains all the addresses a person has.):

Code:
      
<class name="user.UserInfo" table="user_info">
        <id name="id" type="int">
            <column name="id" />
         <generator class="native"/>
        </id>

        ...

        <set name="addresses" table="User_Addr" inverse="false" cascade="all" lazy="true">
         <key column="userId"/>
         <element column="address" type="string" not-null="false"/>
        </set>
</class>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:24 pm 
Newbie

Joined: Tue Jun 20, 2006 3:09 am
Posts: 4
Still waiting...
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 4:33 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You don't? What does a NULL address represent? The system isn't going to know that you want a NULL element in your set when it comes back from the DB.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:27 pm 
Newbie

Joined: Tue Jun 20, 2006 3:09 am
Posts: 4
VampBoy wrote:
You don't? What does a NULL address represent? The system isn't going to know that you want a NULL element in your set when it comes back from the DB.


This is just an example illustrate that a NULL element can not be fetched back after it has been persisted. In real application, this is not address information but other information that null has a specifical meaning.

I also wonder that if it can not be retrieved back, why should hibernate persisted it into database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:29 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Out of curiousity, what is a NULL element persisted as in the DB? You're making it sound like it is actually saving a record?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:53 am 
Newbie

Joined: Tue Jun 20, 2006 3:09 am
Posts: 4
VampBoy wrote:
Out of curiousity, what is a NULL element persisted as in the DB? You're making it sound like it is actually saving a record?


You don't know the null element in database?

null element(address field). NOT NULL record.


Top
 Profile  
 
 Post subject: Re: How to get the null element back?
PostPosted: Thu Jun 22, 2006 7:45 am 
Newbie

Joined: Thu May 04, 2006 4:44 am
Posts: 1
Code:
      
<class name="user.UserInfo" table="user_info">
        <id name="id" type="int">
            <column name="id" />
         <generator class="native"/>
        </id>

        ...

        <set name="addresses" table="User_Addr" inverse="false" cascade="all" lazy="true">
         <key column="userId"/>
         <element column="address" type="string" not-null="false"/>
        </set>
</class>

[/quote]

When writing your query you should make an outer join, something like this:
select adres
from User as user
left outer join user.adress as adress
where user.id = x

Read more about this LEFT OUTER JOIN


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