-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy association to table per class hierarchy does not work
PostPosted: Fri Jan 16, 2009 5:35 pm 
Newbie

Joined: Wed Nov 19, 2008 3:09 pm
Posts: 4
Location: Roseville, CA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.0.1.GA

Mapping documents: Attributes

Code between sessionFactory.openSession() and session.close():
ContactAddressEntity ent = session.Get<ContactAddressEntity>( 25L );
Console.WriteLine( "{0}, {1}", ent.AddressID.ID, ent.AddressID.GetType( ).Name );

Full stack trace of any exception that occurs:
None

Name and version of the database you are using:
SQL Server 2008

I have a ContactAddressEntity with a many-to-one mapping to AddressEntity on the AddressID property of ContactAddressEntity.

Address has a subclass called AKAddressEntity.

If I map AddressID with Lazyness.Proxy I always get an AddressEntityProxy type for the AddressID property. This happens regardless of the descriminator value of the target row. Thus I cannot get to the properties of the AKAddressEntity.

If I map AddressID with Lazyness.False (that being the only change to the mapping) I get the correct AKAddressEntity as expected when the target row contains the discriminator value for AKAddressEntity. Furthermore I also get AddressEntity type when the discriminator value is the default specified for AddressEntity.

So Eager many-to-one associations to table-per-class hierarchy types function as expected. Lazy associasions do not.

Is there any way to get this to work?

_________________
Thanks.
Ken.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 12:26 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look at chapter 16.1.3 of the reference documentation. Sounds like your problem:

http://nhforge.org/doc/nh/en/index.html#performance-fetching-proxies

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 5:19 pm 
Newbie

Joined: Wed Nov 19, 2008 3:09 pm
Posts: 4
Location: Roseville, CA
Yea, according to that there is no way to inject my own load code. So I'm kinda out of luck.

wolli wrote:
Have a look at chapter 16.1.3 of the reference documentation. Sounds like your problem:

http://nhforge.org/doc/nh/en/index.html#performance-fetching-proxies

_________________
Thanks.
Ken.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 2:55 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You could try and implement yor own proxy generator ... but that might be a little bit of an overkill for what you want. But have a look at the nhusers group at google. You can probably find some answers there.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 4:04 am 
Newbie

Joined: Wed Nov 19, 2008 3:09 pm
Posts: 4
Location: Roseville, CA
Actually I thought this was in regards to my other post. I get confused easily :-) Disregard my previous reply.

In this case the way that the sub-class is mapped I should get a proxy to my sub-class (AKAddressEntity), not a proxy to the superclass (AddressEntity).

It's strange that when I set the many-to-one to eager I get the sub-class. It's only when I set the relationship to lazy that I always get the superclass.

Hmm... now that I think about it I guess there's no way for that to happen. It's too bad that the proxy is "pre-loaded".

khadden@starstream.net wrote:
Yea, according to that there is no way to inject my own load code. So I'm kinda out of luck.

wolli wrote:
Have a look at chapter 16.1.3 of the reference documentation. Sounds like your problem:

http://nhforge.org/doc/nh/en/index.html#performance-fetching-proxies

_________________
Thanks.
Ken.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 4:18 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The problem is that hibernate can't know what the concrete class is without touching the database. And the idea of the proxy is to not touch ... so the proxy is build for what is defined in the mapping.

_________________
--Wolfgang


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