We are moving our application from OJB to Hibernate. I am not sure how to map a particular relationship. A client contains 1 or many client groups. Each client group is a part of only one client.
The ClientGroup table contains the client id of it's parent Client.
I have been looking through the documentation and am not sure the best way to map this. I considered a List, but didn't want to add the column to the database if I could avoid it. I was thinking maybe an idbag? Any other suggestions?
Hibernate version:
2.1
Mapping documents:
Code:
<hibernate-mapping schema="ADMSTDDE">
<class name="Client" table="DEXA010T">
<id column="CLIENT_ID" name="id" type="string">
<generator class="assigned"/>
</id>
<property column="NAME" name="name" type="string"/>
<property column="last_name" name="lastClientName" type="string"/>
<property column="LAST_NAME_DT" name="nameUpdateDate" type="date"/>
......
</class>
<class name="ClientGroup" table="DEXA020T">
<id column="CLIENT_GROUP_ID" name="id" type="integer">
<generator class="sequence"/>
</id>
<property column="CLIENT_ID" name="clientId" type="string"/>
<property column="NAME" name="name" type="string"/>
<property column="last_name" name="lastOrganizationName" type="string"/>
.......
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Here is the current code for a client and a client group. This could be changed if it makes the relation easier to map, but this is how it currently is:
ClientCode:
public class Client extends SimpleBean {
public static final int ID_LENGTH = 15;
private String id = null;
private String name = null;
....
private List clientGroups = new ArrayList();
....
}
ClientGroupCode:
public class ClientGroup extends SimpleBean {
protected int id;
private Client client = null;
private String name = null;
....
}
Full stack trace of any exception that occurs:
.
Name and version of the database you are using:
DB2
The generated SQL (show_sql=true):
...
Debug level Hibernate log excerpt:
...