-->
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.  [ 3 posts ] 
Author Message
 Post subject: ManyToMany and IndexColumn: strange SQL update statement
PostPosted: Mon Dec 21, 2009 10:26 am 
Beginner
Beginner

Joined: Tue Nov 03, 2009 9:38 am
Posts: 24
Hi,

I have an entity "Foo" that has a uni-directional many-to-many relationship to another entity "Bar":

Code:
@ManyToMany ( fetch = FetchType.LAZY )
@IndexColumn ( name = "c_index")
@JoinTable ( name = "t_FooBar",
      joinColumns = @JoinColumn ( name = "c_FooUid" ),
      inverseJoinColumns = @JoinColumn ( name = "c_BarUid" ) )
  private List<Bar> bars;


When I execute the following code:
Code:
//update the position of 'bar' within the list
foo.bars.remove(bar);
foo.bars.add( newIndex, bar);

Hibernate issues the following SQL statement:
Code:
/* update collection row Foo.bars */
     update
         t_FooBar
     set
         c_BarUid=?
     where
         c_FooUid=?
         and c_index=?

This, however, causes a constraint violation, since the primary key is (c_FooUid, c_BarUid).
The statement I'd expect is:
Code:
     update
         t_FooBar
     set
         c_index=?
     where
         c_FooUid=?
         and c_BarUid=?

i.e. update the index of (foo,bar) instead of setting a new bar for (foo,index).

Any ideas of how I could change that? Am I missing something?

Thanks in advance.

Regards,

Thomas


Top
 Profile  
 
 Post subject: Re: ManyToMany and IndexColumn: strange SQL update statement
PostPosted: Wed Dec 23, 2009 4:51 am 
Beginner
Beginner

Joined: Tue Nov 03, 2009 9:38 am
Posts: 24
Any ideas?


Top
 Profile  
 
 Post subject: Re: ManyToMany and IndexColumn: strange SQL update statement
PostPosted: Fri Mar 16, 2012 12:38 pm 
Newbie

Joined: Mon Feb 02, 2009 8:56 am
Posts: 6
I'm having this problem too. Hibernate version 3.5.6.

I tried changing my annotation mapping so to mark primary key columns as non nullable, but nothing changes,

Code:
Could not execute JDBC batch update; SQL [update author set author_id=? where book_id=? and index_no=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException...

Does anybody know a workaround for this? Thanks!


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