Hibernate version: 2.0
Name and version of the database you are using: mySQL
The problem I am having feels like a Hibernate bug.
I have worked around the problem, but it is possible that I will simply hit it again later, so it is better to report it.
The problem is to do with the <list> definition detailed below. The Client Business Object (ClientBO) has a one-to-many relationship with the Client Matter Business Object (ClientMatterBO), but when the objects are being populated the ClientMatterBO ArrayList is not getting loaded correctly.
There are two child rows for the ClientBO I am testing. They are uniquely identified by a ClientMatterId. When Hibernate laods these child rows it is putting the objects into ArrayList elements by the identifying id. In my example, the rows are idetified by id=3 and id=99. As you can see below, when I output the ArrayList it has two objects in it, but at element index 3 and index 99.
One possibility is that I should define a hash() method.
Or, there is a bug and Hibernate should just put the two objects into the first two elements in the ArrayList.
The workaround I have is simply to use a <bag> definition instead. However that is unkeyed and when I come to deliver this system I'm sure the users will request the list to be keyed.
Any comments?
Brian
Mapping details:
========================================
<class name="com.abc.model.ClientBO" table="Client">
<id name="ClientId" unsaved-value="0">
<generator class="native"/>
</id>
<list name="ClientMatters" table="ClientMatter" lazy="false" inverse="true" cascade="all-delete-orphan" >
<key column="ClientId"/>
<index column="ClientMatterId"/>
<one-to-many class="com.abc.model.ClientMatterBO"/>
</list>
<property name="ClientCode" type="java.lang.String">
<column name="ClientCode" sql-type="varchar(255)" not-null="true"/>
</property>
<property name="ClientDescription" type="java.lang.String">
<column name="ClientDescription" sql-type="varchar(255)" not-null="false"/>
</property>
</class>
<class name="com.abc.model.ClientMatterBO" table="ClientMatter">
<id name="ClientMatterId" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="ParentClientBO" class="com.abc.model.ClientBO" column="ClientId" not-null="true" unique="false" outer-join="auto" update="true" insert="true" />
<property name="MatterCode" type="java.lang.String">
<column name="MatterCode" sql-type="varchar(255)" not-null="false"/>
</property>
<property name="MatterDescription" type="java.lang.String">
<column name="MatterDescription" sql-type="varchar(255)" not-null="false"/>
</property>
</class>
==========================================
Log excerpt:
==========================================
====>INFO [2004-12-20 15:54:12,186] STDOUT: Hibernate: select clientbo0_.ClientId as ClientId0_, clientbo0_.ClientCode as ClientCode0_, clientbo0_.ClientDesc
ription as ClientDe3_0_ from Client clientbo0_ where clientbo0_.ClientId=?
====>INFO [2004-12-20 15:54:12,186] STDOUT: Hibernate: select clientmatt0_.Cl
ientMatterId as ClientMa1___, clientmatt0_.ClientId as ClientId__, clientmatt0_.
ClientMatterId as ClientMa1_0_, clientmatt0_.ClientId as ClientId0_, clientmatt0
_.MatterCode as MatterCode0_, clientmatt0_.MatterDescription as MatterDe4_0_ from ClientMatter clientmatt0_ where clientmatt0_.ClientId=?
====>INFO [2004-12-20 15:54:12,186] com.abc.web.LoginAction: ClientBO=
ClientBO list=[null, null, null, com.abc.model.ClientMatterBO@1db8f8e, null, nul
l, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, n
ull, null, null, null, null, null, null, null, null, null, null, null, null, nul
l, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, n
ull, null, null, null, null, null, null, null, null, null, null, null, null, nul
l, null, null, null, null, null, null, null, null, null, null, null, null, null,
com.abc.model.ClientMatterBO@1adbfde] and size=100 (Context: Context.
m_SessionId: E363A149D5ABDEE9EAF715E8766FD08B )
====> INFO [2004-12-20 15:54:12,201] STDOUT: Completed action: class com.nps.w
eb.ClientGetAction in 15ms.
========================================
[/code]
|