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: Inheritance issue
PostPosted: Thu Feb 26, 2004 10:54 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Hi,

The application I'm working on use a specific O/R mapping tool that I want to change. So I already have a database model I can't really change.

I have a parent class P and four subclasses A to D which extends P. There is no table for the class P in the database and I do not have a choice, I can't create one for the class P.

I have four tables matching to the classes A to D containing their own attribute (I mean the attributes mapped to the class) and the inherited attributes matching to the class P.

First question is : The table which match to the class B does not contain all the inherited attribute, so is this possible with Hibernate no to have all the inherited attribute in the table, won't it generate an exception?

Second question is : The class D contain two attributes of type java Map and in the database the table matching to class D does not contain anything about the class D but only the inherited attribute, instead there is two tables with the key and the value "Map" and a attribute which is a foreign key to the table matching to class D. Can I do that with Hibernate and how.

Thanks in advance.

Vladislav Pernin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 11:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
This is all covered in the documentation; I highly suggest you sit down and read through it, that really is the best way to learn it.

Quote:
First question is : The table which match to the class B does not contain all the inherited attribute, so is this possible with Hibernate no to have all the inherited attribute in the table, won't it generate an exception?

Just don't map those attributes for that particular subclass. If you don't tell Hibernate about a given (non-existent) column, its not gonna automagically know about it. A better idea would be to partition your class hierarchy a bit better.

Quote:
Second question is : The class D contain two attributes of type java Map and in the database the table matching to class D does not contain anything about the class D but only the inherited attribute, instead there is two tables with the key and the value "Map" and a attribute which is a foreign key to the table matching to class D. Can I do that with Hibernate and how.

Don't quite understand the question here. Do the tables representing the two Maps contained on "D" have a foreign key back to the "D" table? If so, then yes; that's a simple Hibernate Map association.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 12:26 pm 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
I have read the documentation but I'm not sure to understand.

If I use the table per concrete class strategy, it is said that property of "Payment", so the parent class are mapped in the suclasses, is this done automatically? If it is the case, how can I prevent Hibernate to mapped some inherited attributes?

Let me be more precise :

I have a parent class ParentClass, the classes Subclass1 and Subclass2 extend ParentClass.
In the database, there is no table for persisting the attribute of ParentClass, there is two tables named Table1 with all the attribute of the ParentClass and the one of SubClass1, there is also a table Table2 with the attributes of Subclass2 but only some of the attributes of the ParentClass.

So if with this strategy which use implicit polymorphism and that inherited attributed are automatically mapped to the subclasses, how can I do? Second I can't use discriminator.

Hope someone can help.

Vladislav Pernin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 6:40 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Nobody has a response on this issue, if clarification is needed, do not hesitate.

Thanks.

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 7:13 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Actually, when we are talking of inherited attribute, like in the documentation example, where it is said the parent class is not mention, where can I specify the mappings for this class known that there is no table for it (sometimes all, sometimes only a set of the attributes will be stored in the subclass)?

Thanks.

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 7:38 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
I saw something in the doc about the mapping any but I do not really understand to be honest who I could use it in my case.

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 8:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
do you have a class diagram it will more usefull, i think i understand the relationnal requirment.
send it to me a my mail (look my profile), i'll try to help you, i doing inherance with hibernate and it works perfectly


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 12:49 pm 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Thanks to help of delpouve, I have learn about the strategy to use in my case but I still have problem to use it.

I have a mapping file per subclass, no mapping file for the parent class which is like an abstract class.

I have specified the attribute inherited I need in the file and the own class attribute.

I also need a any tag and I guess my problem is here :
<class name="persistence.hib.HibPOJOsubone" table="HibPOJOsubone">
<!-- inherited attributes -->
<id name="id" type="string" unsaved-value="null" >
<column name="HibPOJO_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="name">
<column name="NAME" sql-type="varchar(16)"/>
</property>

<property name="sex"/>

<property name="weight"/>

<!-- own attributes -->
<property name="subone"/>

<any name="persistence.hib.HibPOJO" meta-type="class" id-type="string">
<column name="HibPOJOsubone"/>
<column name="HibPOJO_ID"/>
</any>
</class>

Lets define the test classes I use, HibPOJO is the parent abstract class and HibPOJOsubone and HibPOJOsubtwo are the subclasses.

The table names are the same that the class one. HibPOJO_ID is the id column of the table.

I get a noclassdeffound exception when I call currentSession.

Vlad


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.