Hello everybody,
My problem is about one-to-many associations (as list) and an index attribute (see below), i searched throughout the forums, documentation of hibernate, and google but i can not find the answer. If this question is a duplicate, i am sorry for that.
I have two tables as :
USER
==========
USER_ID______________PK
USER_NAME
USER_STATUS
==============
USER_ID______________PK (FK to USER Table)
USER_STATUS_INDEX____PK (an index)
USER_LEVEL_CODE
UPDATE_DATE
Now this situation is like the example given in Chapter : 23.3.
Customer/Order/Product. But in that example, there are no java classes, only UML diagram is given.
So my mapping file is like that : (By looking to that example)
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="net.domain.User" table="USER" schema="public">
<id name="user_id" type="int">
<column name="USER_ID" />
<generator class="assigned" />
</id>
<property name="user_name" type="string">
<column name="USER_NAME" not-null="true" />
</property>
<list name="user_status" table="USER_STATUS">
<key column="USER_ID"/>
<list-index column="USER_STATUS_INDEX"/>
<composite-element class="net.domain.UserStatus">
<property name="USER_LEVEL_CODE"/>
<property name="UPDATE_DATE"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
Now my questions :
1) Is that mapping file (list section) correct? Should there be another mapping file?
2) How should be the java files? Should there be 2 java files (User, UserStatus)? Should there be a composite-id class for UserStatus or should the primary keys are defined just like attributes?
3) If hibernate will deal with the index attribute, how should be the setter and getter of that index attribute?
Hibernate version: hibernate-3.2.3.ga
Hibernate Tools version: HibernateTools-3.2.0.beta9a
Name and version of the database you are using: postgresql-8.2.3-1
Thank you.