-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with <list> definition
PostPosted: Mon Dec 20, 2004 12:19 pm 
Newbie

Joined: Mon Dec 20, 2004 11:36 am
Posts: 2
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]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 5:42 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
AFAIK, this is the expected behavior. The index property of a list collection is expected to be just that, the index of the object in the list, generally an unique integer column which varies from 0 to n.

Looks like you really do want a set or a bag, possibly sorted by ClientMatterId.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.