Xml – Hibernate mapping error

hibernatexml

I've created a hbm.xml file but it's giving me an 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)*)".

Here's the code:

<?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>

    <class name="edu.byu.training.domain.ProductFlsko" table="PRODUCTFLSKO" schema="GAATTRAINING">
        <property name="productId" column="PRODUCT_ID"/>
        <property name="product" column="PRODUCT"/>
        <property name="description" column="DESCRIPTION"/>
        <property name="price" column="PRICE"/>
        <property name="rowNumber" column="ROW_NUMBER"/>

        <query name="get.By.Id" cacheable="true">
            select ProductFlsko
            from edu.byu.training.domain.ProductFlsko prod
            where prod.productId = :id
        </query>
    </class>
</hibernate-mapping>

I can't figure this out for the life of me…

Best Answer

The class mapping must contain an id or composite-id, see Identifiers in the documentation.

Your id is probably productId.

There are several identity generators.

<class name="edu.byu.training.domain.ProductFlsko" table="PRODUCTFLSKO" schema="GAATTRAINING">
    <id name="productId" column="PRODUCT_ID">
        <generator class="native" />
    </id>
    <property name="product" column="PRODUCT"/>
    <property name="description" column="DESCRIPTION"/>
    <property name="price" column="PRICE"/>
    <property name="rowNumber" column="ROW_NUMBER"/>

    <query name="get.By.Id" cacheable="true">
        select ProductFlsko
        from edu.byu.training.domain.ProductFlsko prod
        where prod.productId = :id
    </query>
</class>
Related Topic