Hi,
I am struggling with the hibernate mapping for a mapping between two tables using a link table. I have the following tables:
customer - customer_key, forename, surname, email
card - card_key, card_number, valid_from, expiries
customer-card - customer_card_key, customer_key, card_key
My mapping file is:
<?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 entity-name="card" table="card" lazy="false">
<id name="id" column="card_key" type="integer">
<generator class="native" />
</id>
<property name="cardNumber" column="cardNumber" not-null="true" type="string" />
<property name="validFrom" column="valid_from" not-null="true" type="string" />
<property name="expires" column="expires" not-null="true" type="string" />
</class>
<class entity-name="customer" table="customer" lazy="false">
<id name="id" column="customer_key" type="integer">
<generator class="native" />
</id>
<property name="forename" column="forename" not-null="true" type="string" />
<property name="surname" column="surname" type="string" />
<property name="email" column="email" type="string" />
<idbag name="cards" table="customer-card">
<collection-id type="integer" column="customer_card_key" >
<generator class="native" />
</collection-id>
<key column="customer_key"/>
<many-to-many entity-name="card " column="card_key" fetch="select" />
</idbag>
</class>
</hibernate-mapping>
The error I get is:
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping card
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addXML(Configuration.java:440)
Please remember that I am using the dynamic mode MAP and not POJO.
Thanks for your help.
CTO
|