Vadim Vadim - 3 months ago 17
Java Question

Hibernate mapping "class" must match

I have next message error with red line under

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*,fetch-profile*,resultset*,(query|sql-
query)*)".


I'm trying to create
POJO
classes with mapping file of the next part of Oracle HR Scheme.

Employees
Employee_id
first name
last_name
....
department_id


many to one

Departments
department_id
department_name
manager_id
location_id


many to one

Locations
location_id
...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name = "employee.Department" table="DEPARTMENTS">
<meta attribute="class-description">This class contains the department records.</meta>
<id name = "id" type = "int" column="department_id"/>
<many-to_one name="location" column = "location_id"
class = "employee.Location" not-null = "true"/>
</class>
<class name = "employee.Location" table="LOCATIONS">
<meta attribute="class-description">This class contains the locations records.</meta>
<id name = "id" type = "int" column="location_id"/>
<property name="streetAdress" column = "street_adress" type = "string"/>
<property name="postalCode" column = "postal_code" type = "string"/>
<property name="city" column = "city" type = "string"/>
<property name="stateProvince" column = "state_province" type = "string"/>
<property name="country_id" column = "country_id" type = "string"/>
</class>
</hibernate-mapping>

RC. RC.
Answer

As stated by the error message, the <class> tag can have a variety of children but <many-to_one> (note the _) is not an allowed child.

Comments