-->
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.  [ 4 posts ] 
Author Message
 Post subject: OneToMany with IndexColumn can't be saved?
PostPosted: Fri Dec 22, 2006 11:21 am 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
Hi All,

A while back I was having trouble with "cannot load multiple bags" errors during eager fetching. So, I added @IndexColumn annotations to all my @OneToMany mapping to enforce the "List semantic".

But, now I'm having trouble with removing entities from OneToMany mappings defined as follows:

@OneToMany(targetEntity = AbstractInstrumentImpl.class)
@IndexColumn(name = "inst_order")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Cascade(value = { org.hibernate.annotations.CascadeType.ALL })
public List<Instrument> getInstruments()
{
return instruments;
}

I use the hibernate tools ant task to produce the SQL for schema generation. This produces the following link table:

create table subportfolio_instrument (
subportfolio_id numeric(19,0) not null,
instruments_id numeric(19,0) not null,
inst_order int not null,
primary key (subportfolio_id, inst_order),
unique (instruments_id)
);

If I remove an instrument from the collection and save the subportfolio the following happens:

- The row with the highest inst_order value for the subportfolio in question is deleted (to make the collection one smaller). No problem here.

- It seems that the remaining rows are updated one by one to hold the correct instruments_id value. But this causes the "unique (instruments_id)" constraint to be broken, which causes the save to fail.

Is this expected? Can I change the annotations to stop this happening?

I started seeing this when the number of items in the collection was bigger than the batch size. Turning off batching makes the problem happen every time.

Any help anyone can give me would be greatly appreciated.

Thanks.
Ashley


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 6:06 pm 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
I think I'm seeing the same thing as this person did:

http://forum.hibernate.org/viewtopic.php?t=960495

This seems pretty fundamental so I'm bound to have configured things incorrectly. Can anyone point me in the right direction?

Thanks.
Ashley


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 5:49 am 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
This bug describes the problem:

http://opensource.atlassian.com/project ... e/HHH-1268


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 7:04 am 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
I've added @JoinColumn to remove the link table (and keep the List semantic) to work around the problem.

Can anyone confirm that this is a real bug? Or is simply misconfiguration on my part?

I'd prefer to keep the link table if possible...


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