chinanihc2 wrote:
Hey, here´s my case:
TABLE PRODUCT
- PNUMBER (PK)
- NAME
- ...
TABLE PRODUCT_TYPE
- PNUMBER(PK/FK)
- TYPE(PK/FK)
- ...
TABLE TYPE
- TYPE(PK)
- DESCRIPTION
- ...
How can i map type into product? Is there a way? I do not have the TYPE info anywhere else in the system(it´s a legacy system...)! thanks!!!
Here is your mapping:
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 package="model">
<class name="Product" table="PRODUCT">
<id name="pnumber" column="pnumber" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="name" column="NAME" type="java.lang.String" />
</class>
<class
name="ProductType"
table="PRODUCT_TYPE" >
<id name="type" column="TYPE" type="java.lang.Integer">
<generator class="native"/>
</id>
<many-to-one
name="product"
column="pnumber"
class="product"
not-null="true" />
<joined-subclass
name="Type"
table="TYPE" >
<key column="type" />
</joined-subclass>
</class>
</hibernate-mapping>
but you will be needed to change id generators to your DB ability
It should work