-->
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.  [ 1 post ] 
Author Message
 Post subject: Property value class with subclass of subclass
PostPosted: Fri May 13, 2011 6:31 pm 
Newbie

Joined: Fri May 13, 2011 6:09 pm
Posts: 1
Hi all,

I have run into an issue with a 3-level class hierarchy and I wonder if there is some nice way to solve it.

I have a class hierarchy with a parent, 2 childs and a grand-child, mapped like this.

Code:
<class name="Resource" table="RESOURCE" entity-name="RESOURCE">
    <discriminator column="TYPE" type="string" length="1" />
    <subclass class="Group" discriminator-value="G" entity-name="GROUP">
    </subclass>
    <subclass class="User" entity-name="USER">
        <subclass class="RegisteredUser" discriminator-value="R" entity-name="REGISTERED_USER">
        </subclass>
        <subclass class="UnregisteredUser" discriminator-value="U" entity-name="UNREGISTERED_USER">
        </subclass>
    </subclass>
</class>


and some other class with an assoziation

Code:
<many-to-one name="owner" column="OWNER_ID" entity-name="RESOURCE" />


Now, checking the owner class along

Code:
obj.getOwner().getClass().getName()


I get the real class for a Group (which is on the 1st level of the hierarchy) and instanceof etc. work nicely. Howver, for an UnregisteredUser as well as a RegisteredUser (2nd level of the hierarchy) I usually get a Proxy and all kind of comparisons to the expected classes as well as casting fails.

I found that the issue does vanish if I turn off lazy-fetching on the assocization and explicitly loading the owner by ID anew will result in the correct class as well. I tried using abstract="true" on the common parent ("User") as it is actually an abstract class and tried setting a discriminator for it as well - neither helps.

Is there any other "nicer" way than turning of lazy-fetching or reloading the object to be able to cast or check the class?

Cheers,
Sven


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.