-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inheritance problem
PostPosted: Mon Feb 22, 2010 2:14 pm 
Newbie

Joined: Mon Feb 22, 2010 2:02 pm
Posts: 1
Hello, I'm having a big problem with hibernate I can't seem to solve.
I have 2 java classes :
CMinimalProfile and CProfile. CProfile extends CMinimalProfile

CMinimalProfile only contrains the id of the profile whereas CProfile contains a ton of information. I don't want to send the full profile to the client when only the ID is needed.

In my database I only have one table tprofile

I made two mapping files, one for each class.
cminimalprofile.hbm.xml :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="profile.CMinimalProfile" table="tprofile" >
<id name="id" type="int" column="id_profile">
<generator class="increment" />
</id>
</class>
</hibernate-mapping>


cprofile.hbm.xml :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class
name="profile.CProfile"
table="tprofile" >

<id name="id" type="int" column="id_profile">
<generator class="increment" />
</id>

<property name="name">
<column name="name" />
</property>

... a bunch of properties ...
</class>

the mapping seems to work, but when I try to query CMinimalProfiles here is what happens :

Say I have 2 profiles in my table tprofiles.

=> session.createQuery("from CMinimalProfile").list()

I would like this to return a list with two CMinimalProfiles with their id filled up.
BUT for some reason i fail to understand, the list does not contain 2 items but FOUR.

I get the 2 CMinimalProfiles I wanted, but I also have 2 extra objects of class CProfile in the list.

I don't understand why it happens...

I tried to use hibernate inheritance mechanisms but it didn't work either, I tried to implement inheritance in my database too but it doesn't work because PostgreSQL inheritance seem to have problems with foreign keys and subtables but this is an other issue I guess.

Anyway, can someone explain why with the above exemple, hibernate returns a list of 4 objects instead of just two ?

Thank you for your answers.


Top
 Profile  
 
 Post subject: Re: Inheritance problem
PostPosted: Mon Feb 22, 2010 6:11 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
This is called implicit polymorphism, and is described in the documentation http://docs.jboss.org/hibernate/stable/ ... lymorphism

It can be disabled for a class by mapping it with:

Code:
<class ... polymorphism="explicit"...>


Here is an example: http://docs.jboss.org/hibernate/stable/ ... tion-class


Top
 Profile  
 
 Post subject: Re: Inheritance problem
PostPosted: Mon Apr 19, 2010 12:30 am 
Newbie

Joined: Sun Dec 13, 2009 4:14 pm
Posts: 10
Can we create implicit poly morphism relationship while reverse engineering through hibernate tools? Moreover, do we have any nice example for implementing implicit polymorphism using annotations.


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