-->
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: Persistent Set Iterator
PostPosted: Thu Feb 24, 2005 3:09 am 
Newbie

Joined: Thu Feb 24, 2005 2:49 am
Posts: 3
This is a possible bug I noticed. I am using the Hibernate CVS Head. Has anyone testing the latest, greatest and breakiest noticed this?

I have a PersistantSet which contains only a composite-element. However as soon as I call iterator() on the set I trigger some sort of update on the set.

AbstractPersistentCollection v1.15
PersistentSet v1.12

Mapping:

<set name="prices" table="product_price" sort="natural">
<key column="item_id"/>
<composite-element class="ProductPrice">
<property name="qty"/>
<property name="price"/>
</composite-element>
</set>

Table: (MySQL 4.1)

CREATE TABLE `product_price` (
`item_id` bigint(20) NOT NULL default '0',
`qty` int(11) NOT NULL default '0',
`price` float NOT NULL default '0',
UNIQUE KEY `item_id` (`item_id`,`qty`)
)

Java:

getPrices().iterator();

If the set is sorted (with sort="natural") It tries to do this SQL:

Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)
Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)
Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)

Which produces a unique key error (the rows are already in the table and the set hasn't been modified by my code)

If the set isn't sorted (no sort attr) It does this SQL:

Hibernate: delete from product_price where item_id=? and qty=? and price=?
Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)
Hibernate: delete from product_price where item_id=? and qty=? and price=?
Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)
Hibernate: delete from product_price where item_id=? and qty=? and price=?
Hibernate: insert into product_price (item_id, qty, price) values (?, ?, ?)

Basically it deletes all the rows and reinserts them. This actually works, but seems superfluous.

If you don't use the iterator it doesn't do either. I presume it doesn't actually initialize the set contents either.

So am I the only one? Has anyone else seen this sort of behavior?


Top
 Profile  
 
 Post subject: Please Ignore
PostPosted: Mon Feb 28, 2005 4:31 am 
Newbie

Joined: Thu Feb 24, 2005 2:49 am
Posts: 3
Since no one commented on this. I decided it must be a bug on my part, and it was as stupid as a typo in the word hashCode.

Please ignore.


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.