-->
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.  [ 8 posts ] 
Author Message
 Post subject: many-to-one lazy="proxy" explanation
PostPosted: Tue Mar 28, 2006 3:55 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Hibernate version:3.1.3

What exactly lazy="proxy" means ?

I read http://www.hibernate.org/hib_docs/v3/re ... manytoones

but the proxy option is not detailed. I doesn't do anything from what I see.
When I access the associated object nothing happends

I have a participant that has a prefix. If I call
participant.getPrefix().getName()
the Name stays null, even though the prefix's id is valid.

Thanks,
Q


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 5:49 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
the values are lazy="false|no-proxy|proxy"

no-proxy and proxy are basically saying "true" you want it to initialize LATER... (meaning at the time you first access the object - thus you may see an extra select at this time).

The difference between those two are:

1) no-proxy will not provide a proxy object
2) proxy will.

check out your debugger and examine what the "type" is of the object you are looking at and you'll see that your object is actually handled by a CGLIB object which extends your object (the proxy object).

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 6:27 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
I was expecting in case of "proxy" to see the extra database call. But nothing happened and I was suprised. I will change it to no-proxy to see if that behaves differently. "No-Proxy" should update my object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 7:11 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
lazy="no-proxy" requires build-time bytecode instrumentation

see reference.pdf for that.

http://www.hibernate.org/hib_docs/v3/reference/en/pdf/hibernate_reference.pdf

you should have notice a value when you accessed it.
I think your actual object is prefix right? and Name (ie, col in db) is the attribute off of it? is Name==null in your db?

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 10:54 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
It's funny ! I don't get anything.

Prefix is an object ( ListItem(id, name, desc) ) that is selected in a web form, so it's id is populated. Then I do store in the participant with session.save(participant). All gets saved right.

Right after save I do want to know the prefix name so I will email the participant. I called participant.getPrefix().getName() but it returns right away an no debug statements in my console.

Seems that I have to force it (Hibernate.initialize( prefix ) )...

The mapping of prefix in Participant is done like this
<many-to-one name="prefix" class="ListItem" column="prefix_id" not-null="true" lazy="no-proxy"/>

I tried but proxy and no-proxy - nothing happend.
The many-to-one is unu-directional - present only in participant.

Thanks for looking!
Q


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 1:37 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
maybe you can create a small test case and post it.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 2:35 am 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
I don't think I do something wrong. The example is extremelly simple.

Here some more interesting things.

1. If I do lookup a participant and then try to access the prefix. I see the query and the prefix object gets fully populated. So the mapping is right.

2. As I said this happend in a post save() call. So I save the participant and right after that I try to load prefix but no success.

3. I'm thinking that the state of the participant after save() must not be right or something. I tried to call Hibernate.initiliaze( participant.getPrefix() ) and nothing happens.

I will enable my logs and find out more.


Thanks,
Q


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 10:50 am 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
If I evit the pax from session, right after save, all is good!


if ( session.contains( pax ) )
{
session.evict( pax );
}


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