Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mapping question (hashmap and subclasses)

 
Elax Grandel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a table-per-class-hierarchy style with an Employee superclass and two subclasses, Manager and Salesman. All Employees map to a table emp_ids. The Employee class also has a hashmap inside it which is supposed to map to the table emp_attributes.

I am getting the error: The content of element type "class" must match (meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),
discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|
one-to-one|component|dynamic-component|properties|any|map|set|list|bag|
idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|
union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,
resultset*,(query|sql-query)*)".

This is the mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="npackage.employee">


<class name="Employee" table="emp_ids" dynamic-insert="true" dynamic-update="true">
<id name="emp_id" column="emp_id">
<generator class="increment"/>
</id>

<discriminator column="emp_type" type="string" />
<subclass name="Manager" discriminator-value="Manager"></subclass>
<subclass name="Salesman" discriminator-value="Salesman"></subclass>

<map name="attributeMap" table="emp_attributes">
<key column="emp_id"/>
<map-key type="integer" column="attribute_key"/>
<element type="string" column="attribute_value"/>
</map>

</class>
</hibernate-mapping>

I'm a newbie in Hibernate, XML, and reading DTDs so to me it looks like this mapping does match the DTD of the class element. Can anyone tell me what is wrong with it?

Please ignore any design issues or anything unrelated to this mapping for now. Thank you for your help.
[ April 07, 2008: Message edited by: ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"tegojo",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.
 
Elax Grandel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, name has been changed.

Now, for my problem -- if it helps, the error disappears when I put the map element within each subclass element. I want to avoid having to do this for each subclass since it will be the same for each and every one. Is it possible to declare one map element for the entire class and not for each subclass?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="npackage.employee">


<class name="Employee" table="emp_ids" dynamic-insert="true" dynamic-update="true">
<id name="emp_id" column="emp_id">
<generator class="increment"/>
</id>

<discriminator column="emp_type" type="string" />
<subclass name="Manager" discriminator-value="Manager">
<map name="attributeMap" table="emp_attributes">
<key column="emp_id"/>
<map-key type="integer" column="attribute_key"/>
<element type="string" column="attribute_value"/>
</map>
</subclass>

<subclass name="Salesman" discriminator-value="Salesman">
<map name="attributeMap" table="emp_attributes">
<key column="emp_id"/>
<map-key type="integer" column="attribute_key"/>
<element type="string" column="attribute_value"/>
</map>
</subclass>



</class>
</hibernate-mapping>

[ April 07, 2008: Message edited by: Elax Grandel ]
[ April 07, 2008: Message edited by: Elax Grandel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic