-->
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.  [ 6 posts ] 
Author Message
 Post subject: idbag and bidirectional many-to-many
PostPosted: Wed Dec 03, 2003 9:52 am 
Newbie

Joined: Wed Dec 03, 2003 9:41 am
Posts: 7
Location: Stockholm, Sweden
Hello

I have a bidirectional many-to-many relationship between two entities.
I would like to use the idbag, but there seems to be no inverse attribute for the idbag tag (as exists for set, list, bag etc).
Is that not needed or is it simply missing.

///Odd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 9:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
For the inverse="true" end of a bidirectional idbag, just use an ordinary bag ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 10:56 am 
Newbie

Joined: Wed Dec 03, 2003 9:41 am
Posts: 7
Location: Stockholm, Sweden
Thanks!

Now I get another problem :)

On the idbag side I set the collection-id to use a native generator, resulting in the following generated Hibernate create statement:
Code:
create table AccountGroupMember (
   memberId NUMERIC(19,0) not null,
   groupId NUMERIC(19,0) not null,
   id INT IDENTITY NOT NULL,
   primary key (id)
)

But when I add add an entity to the relation, Hibernate throws a class cast exception:
Code:
java.lang.ClassCastException
   at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
   at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
   at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
   at net.sf.hibernate.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:401)
   at net.sf.hibernate.collection.IdentifierBag.writeTo(IdentifierBag.java:291)
   at net.sf.hibernate.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:622)
   at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:49)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2303)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2259)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2182


The value passed to IntegerType.set() is an empty String.
It looks like the Hibernate generated SQL insert statement (for the relation table) is incorrect:
Code:
  insert into AccountGroupMember (memberId, id, groupId) values (?, ?, ?)

Isn't the database (MS SQL Server in this case) supposed to set the id value itself (as it is an IDENTITY column), and thus the insert statement rather be:
Code:
  insert into AccountGroupMember (memberId, groupId) values (?, ?)


Or maybe I've just misunderstood something here...

///Odd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
sorry, idbag doesn't support identity columns yet - you have to use a different id generator :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:11 am 
Newbie

Joined: Wed Dec 03, 2003 9:41 am
Posts: 7
Location: Stockholm, Sweden
Oops!
Should have checked the documentation one more time. Sorry!

///Odd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 4:12 pm 
Newbie

Joined: Thu Jan 06, 2005 4:41 pm
Posts: 8
Is it implemented now in hibernate 3?

Thanks.


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