-->
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.  [ 5 posts ] 
Author Message
 Post subject: Duplicate result in XML Mapping
PostPosted: Wed May 24, 2006 11:00 pm 
Newbie

Joined: Wed May 24, 2006 10:32 pm
Posts: 4
I met a strange problem when using XML Mapping.

See the following map file I use for testing.

<hibernate-mapping auto-import="false">
<class entity-name="Master" table="MasterTable" node="Master">
<id name="id" type="string" column="M_ID" node="@id"/>
<property name="name" type="string" column="M_Name" node="@name"/>
<set name="details" node="Details" embed-xml="true" fetch="join">
<key column="MasterTable" not-null="true"/>
<one-to-many entity-name="Detail"/>
</set>
</class>
<class entity-name="Detail" table="DetailTable" node="Detail">
<id name="id" type="string" column="D_ID" node="@id"/>
<property name="name" type="string" column="D_Name" node="@name"/>
<set name="anothers" node="Anothers" embed-xml="true" fetch="join">
<key column="DetailTable" not-null="true"/>
<one-to-many entity-name="Another"/>
</set>
</class>
<class entity-name="Another" table="AnotherTable" node="Another">
<id name="id" type="string" column="A_ID" node="@id"/>
<property name="name" type="string" column="A_Name" insert="false" update="false" node="@name"/>
</class>
</hibernate-mapping>

The result XML is:

<?xml version="1.0" encoding="UTF-8"?>
<Master id="master1" name="Master1">
<Details>
<Detail id="detail1" name="Detail1">
<Anothers>
<Another id="another1" name="Another1"/>
<Another id="another3" name="Another3"/>
</Anothers>
</Detail>
<Detail id="detail1" name="Detail1"> //same set is duplicated
<Anothers>
<Another id="another1" name="Another1"/>
<Another id="another3" name="Another3"/>
</Anothers>
</Detail>
<Detail id="detail2" name="Detail2">
<Anothers>
<Another id="another2" name="Another2"/>
<Another id="another4" name="Another4"/>
<Another id="another5" name="Another5"/>
</Anothers>
</Detail>
<Detail id="detail2" name="Detail2"> //duplicate again. It seems that the duplicate is according to the number of the children.
<Anothers>
<Another id="another2" name="Another2"/>
<Another id="another4" name="Another4"/>
<Another id="another5" name="Another5"/>
</Anothers>
</Detail>
<Detail id="detail2" name="Detail2">
<Anothers>
<Another id="another2" name="Another2"/>
<Another id="another4" name="Another4"/>
<Another id="another5" name="Another5"/>
</Anothers>
</Detail>
</Details>
</Master>

This problem is really strange. It seem either I or the Hibernate do something wrong. Is there anyone knows why?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:04 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
My first thought would be that your hashCode (and therefore your equals) methods are wrong. Read up on how to write hashCodes for persistent classes, and ensure that you're following the hibernate rules.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:19 pm 
Newbie

Joined: Wed May 24, 2006 10:32 pm
Posts: 4
tenwit wrote:
My first thought would be that your hashCode (and therefore your equals) methods are wrong. Read up on how to write hashCodes for persistent classes, and ensure that you're following the hibernate rules.


Thank for reply me so quickly.

However, there is no beans in this scenario, only the map file. Since we are using AJAX in web tier, we want to use XML mapping and fetch XML result directly from the database. Thus, we can avoid lots of meaningless beans and reflection.

As for the "hashCode", I think there must be some alternative feature in the Hibernate map file. What can I do then?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:27 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I don't know how to specify business keys in this scenario. There are two things you could try:

1) Change from <set> to <bag>. This works well if the tables are read-only, but you may run into efficiency problems if they're read-write and the collections can be large.

2) Omit all your fetch="join" attrbiutes, and go with the default fetch="select".

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:53 pm 
Newbie

Joined: Wed May 24, 2006 10:32 pm
Posts: 4
tenwit wrote:
I don't know how to specify business keys in this scenario. There are two things you could try:

1) Change from <set> to <bag>. This works well if the tables are read-only, but you may run into efficiency problems if they're read-write and the collections can be large.

2) Omit all your fetch="join" attrbiutes, and go with the default fetch="select".


Approach 2 is okay. Actually, it is what I do in my first testing. However, if the collections are large, the efficiency is a problem.

In our project, we want to develop a BPM platform. Modeling the business entity is quite a challenge. Before we start, we decide to have enough testing of current ORM approach. Some testings are really extreme. Master-Detail-SubDetail structure is rather complex but an actual requirment for some application. Sometime the collection can be very large.

Well, lazy load can work. However, the bottleneck is not always in the database. We have tried fetching Master-Detail-SubDetail tables in a large database which has 1000'000 records. Using join syntax, it takes 2 second for MS SQL Server to generate results. This performance is allowable. In some cases, loading such a large dataset is useful, to do some complex calculation etc. Lazy load is this case seems lower the performance.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.