One-to-One Bar Chart Offset with Reference Column (XML Mapping)
I have a user table user_detail
and a user_detail
one-to-one mapping table have a field user_id
to be used for this relationship that stores the value of the corresponding user id field.
How do I write the hibernate file hbm
for this relationship?
UPDATE
What is my problem is that the primary key of the user id
, the foreign key user_detailuser_id
all examples i got in internet user user_id as primary key of user and same as foreign key in other table
source to share
For user matching ....
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 25 April 2011 7:52:33 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.rais.User" table="USER" catalog="mydb">
<id name="userId" type="java.lang.Integer">
<column name="USER_ID" />
<generator class="identity" />
</id>
<property name="userName" type="string">
<column name="USER_NAME" length="10" not-null="true" unique="true" />
</property>
<property name="userCode" type="string">
<column name="USER_CODE" length="20" not-null="true" unique="true" />
</property>
<one-to-one name="userDetail" class="com.rais.UserDetail"
cascade="save-update"></one-to-one>
</class>
</hibernate-mapping>
For matching UserDetail.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 25 April 2011 7:52:33 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.rais.UserDetail" table="USER_DETAIL"
catalog="mydb">
<id name="userId" type="java.lang.Integer">
<column name="USER_ID" />
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<one-to-one name="user" class="com.rais.User"
constrained="true"></one-to-one>
<property name="compName" type="string">
<column name="COMP_NAME" length="100" not-null="true" />
</property>
<property name="compDesc" type="string">
<column name="COMP_DESC" not-null="true" />
</property>
<property name="remark" type="string">
<column name="REMARK" not-null="true" />
</property>
</class>
</hibernate-mapping>
source to share
<one-to-one name="user_detail" class="give the full specified className with package declaration" cascade="save-update"></one-to-one>
Here's a good example
http://www.mkyong.com/hibernate/hibernate-one-to-one-relationship-example/
please find it.
source to share