-->
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.  [ 2 posts ] 
Author Message
 Post subject: Many-to-one not being populated on fetch
PostPosted: Sun May 15, 2005 12:32 am 
Newbie

Joined: Sun May 15, 2005 12:01 am
Posts: 8
A simple many-to-one mapping returns an 'empty' object (all properties are null) unless it was previously fetched in the session. Am I doing something wrong ?


Two entities CallBean & DChannelBean, both use Long for ID, all properties are access="field"


Failure Case:

Code:
  c = (CallBean)s.get( CallBean.class, (Long)cid );

  System.out.println( "Call "+c.id+" D "+c.dChannel.id+"  should be "+did );

OUTPUT
Call 2 D null  should be 1


Success Case:

Code:
  d = (DChannelBean)s.get( DChannelBean.class, (Long)did );
  c = (CallBean)s.get( CallBean.class, (Long)cid );

  System.out.println( "Call "+c.id+" D "+c.dChannel.id+"  should be "+did );

OUTPUT
Call 2 D 1  should be 1


-----------------

Here's the relevant xml..

Code:
<class name="CallBean" table="CALL">
   <many-to-one name="dChannel"
                column="D_CHANNEL_ID"         
                access="field"
                class="DChannelBean"/>




Using Hibernate 3.0.3
Java 1.5.0_03

Tried on Postgres 8 and Oracle 10


Top
 Profile  
 
 Post subject: Re: Many-to-one not being populated on fetch
PostPosted: Sun May 15, 2005 1:22 am 
Newbie

Joined: Sun May 15, 2005 12:01 am
Posts: 8
Hmm,

I became suspicious of accessing the attribute directly as I wrote my post. After searching the posts on such topics I think I now understand what's going on under the hood a little better. I Changed my code to use getters/setters and it worked.

I guess this is a hidden side-effect of the byte-code mods going on. The POJO isn't quite as plain as it appears in your class. The getter/setter has 'hidden' functionality to fill in the object at the last moment.

I thought I had combed the docs pretty well, but never noticed info on this topic. Did I just miss it? If not, it might be a good thing to add (perhaps in the FAQ).

If someone 'in the know' could just confirm/deny my new view of the world, I'd appreciate it.

Craig


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