-->
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: problem about inheritance
PostPosted: Wed Dec 06, 2006 6:05 am 
Newbie

Joined: Wed Dec 06, 2006 5:54 am
Posts: 3
I'm reading and following the tutorial but I'm not able to define mapping files for inheritance.
This are my classes:

public class Author
private Vector <Album> allAlbum;
private String artName;

public class Artista extends Author
private String name;
private String surname;

public class Band extends Author
private Vector<String> components;

and this is the mapping file for Author:

<hibernate-mapping default-access="field" default-lazy="false"
default-cascade="save-update">
<class name="oodb.Author" table="author">
<id column="author_id" type="long">
<generator class="native"/>
</id>
<discriminator column="author_type" type="string"/>
<property name="artName"/>
<array name="allAlbum" table="album">
<key column="author_id"/>
<list-index column="sortOrder"/>
<one-to-many class="oodb.Album"/>
</array>
<subclass name="oodb.Band" extends="oodb.Author" discriminator-value="band">

<key column="author_id"/>
<array name="components" table="components">
<key column="author_id"/>
<list-index column="sortOrder"/>
<element column="component" type="string"/>
</array>

</subclass>
<subclass name="oodb.Artista" extends="oodb.Author" discriminator-value="solista">

<key column="author_id"/>
<property name="name" column="name"/>
<property name="surname" column="surname"/>

</subclass>

</class>
</hibernate-mapping>

I obtain the following error:

10:29:04,531 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(31) The content of element type "subclass" must match "(meta*,tuplizer*,synchronize*,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,join*,subclass*,loader?,sql-insert?,sql-update?,sql-delete?,resultset*,(query|sql-query)*)".
10:29:04,533 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(40) The content of element type "subclass" must match "(meta*,tuplizer*,synchronize*,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,join*,subclass*,loader?,sql-insert?,sql-update?,sql-delete?,resultset*,(query|sql-query)*)".

and I don't understand because I just follow what is written in the guide.
I'm sorry if it's a stupid question, I'm new to Hibernate and I searched on the net and tutorial, but didn't find much about this error.
If someone can help me or give me a reference for this I would be grateful.
thanks to all


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 6:45 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
What is the mean of the <key> elements in subclasses mapping? How i understand, you trying to map "table-per-class heierarchy" strategy, when all subclasses resides in one table with discriminator column. So, why you put <key> elements?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 9:25 am 
Newbie

Joined: Wed Dec 06, 2006 5:54 am
Posts: 3
you are right. I was trying different combinations of tables and subclasses.
By the way,,,
...I was able to let it work in table per subclass mode, removing the <array> tag in the subclass.

now I need to know how I can map a Vector<String> object inside a subclass if I can't use <array>.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 9:51 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
why you use a vector? you can use a list and map it with bag


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 11:41 am 
Newbie

Joined: Wed Dec 06, 2006 5:54 am
Posts: 3
Ok, i tryed to use List<String> and bag but.... It gives the same error with bag!
My mapping file is:

<hibernate-mapping default-access="field" default-lazy="false"
default-cascade="save-update">
<class name="oodb.Author" table="author">
<id column="author_id" type="long">
<generator class="native"/>
</id>
<discriminator column="author_type" type="string"/>
<property name="artName"/>
<array name="allAlbum" table="album">
<key column="author"/>
<list-index />
<one-to-many class="oodb.Album"/>
</array>

<subclass name="oodb.Band" extends="oodb.Author" discriminator-value="band">
<join table="band">
<key column="band_id"/>
<property name="components" type="class"/>
<bag name="components" table="components">
<key column="comp_id" />
<element column="comp" type="string"/>
</bag>
</join>
</subclass>

<subclass name="oodb.Artista" extends="oodb.Author" discriminator-value="solista">
<join table="solista">
<key column="artist_id"/>
<property name="name" column="name"/>
<property name="surname" column="surname"/>
</join>
</subclass>

</class>
</hibernate-mapping>

and the error:

16:35:48,663 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(36) The content of element type "join" must match "(subselect?,comment?,key,(property|many-to-one|component|dynamic-component|any)*,sql-insert?,sql-update?,sql-delete?)".

it doesn't want tags different from "property","many-to-one","component" inside the <join> tag.
But I don't know how to map a List<String> or Vector<String> object related to a subclass.
what is wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 1:36 pm 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
it is right, but i think 3 table for same class hierarchy is not good thing.

from hibernate doc, about join:

"This feature is often only useful for legacy data models, we recommend fewer tables than classes and a fine-grained domain model. However, it is useful for switching between inheritance mapping strategies in a single hierarchy, as explained later."

so it's better you create one table , for class artist and his subclasses.


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.