-->
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: Inheritance mapping and Java generics
PostPosted: Thu Jul 02, 2009 10:24 am 
Newbie

Joined: Wed Jan 31, 2007 10:26 am
Posts: 1
I implemented an inheritance mapping by using the table per class hierarchy strategy. This works fine as long as I directly retrieve objects by id. As soon as I retrieve them via other classes (connected by foreign keys inside the database), I'm getting an object of the base class of the hierarchy only. I did it like that (simplified):

Java:
Code:
public class SampleBaseClass<T> {
  private Set<SampleConnectedClass> sampleSubClass = new HashSet<SampleConnectedClass>(0);
}

public class SampleSubClass extends SampleBaseClass {
}

public class SampleConnectedClass {
  private SampleBaseClass<?> sampleBaseClass;

  public SampleBaseClass<?> getSample() {
    return this.sampleBaseClass;
  }
}

Mapping:
Code:
<hibernate-mapping>
  <class name="SampleBaseClass" table="sample_base" schema="public">
    ...
    <discriminator column="subclass_identifier" type="string" />
    ...
    <subclass name="SampleSubClass" discriminator-value="sub" />
  </class>
</hibernate-mapping>

<hibernate-mapping>
  <class name="SampleConnectedClass" table="sample_connected" schema="public">
    ...
    <many-to-one name="sample" class="SampleBaseClass" fetch="select" cascade="save-update">
      <column name="id_sample_base" not-null="true" />
    </many-to-one>
  </class>
</hibernate-mapping>


Now when calling:
Code:
SampleConnectedClass().getSample()

I'm always getting SampleBaseClass even if it should return SampleSubClass. If I retrieve the object directly from Hibernate by id, everything works fine.

Any ideas what I am doing wrong?

Thanks in advance,
Roman


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.