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.  [ 8 posts ] 
Author Message
 Post subject: Many to Many relationship with integer array
PostPosted: Wed Aug 22, 2007 11:10 am 
Newbie

Joined: Wed Aug 22, 2007 11:00 am
Posts: 3
Hibernate version:1.20

Name and version of the database you are using:MS SQL 2000

Hi,
Im very new to nhibernate and im trying to map an array I have that is full of int32's to a join table in sql server 2000.

I have an instrument class and a setType class. Basically a setType is a box full of instruments. When defining a new setType the user adds what instruments are in this setType.

I have an integer array as part of the setType class and it is populated with the correct instrument Id's etc... However when i save this the object is saved in the database but there are no entries on the setTypeInstrument table(the join table which just contains setTypeID and instrumentID)

All the nhibernate code is in a web service.

here is the part of the mapping file thats not doing what it should

<set name="instrumentIDs" table="setTypeInstrument" lazy="true">
<key column="setTypeID" />
<many-to-many class="WSAuralia.Instrument" column="instrumentID" />
</set>

anyone any ideas? It's breaking my heart!!

Cheers
Ian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 12:14 pm 
Newbie

Joined: Fri Jul 20, 2007 7:45 pm
Posts: 12
Location: Amgen Corp
Hi Ian,

Have you tried adding the 'cascade' attribute to your set tag? I am a newbie, and I've only done a 'one-to-many' association. When I first tried to save my object, the object properties that were underpinned by the primary table got persisted, but the collection didn't get persisted to its table. That didn't happen until I added the cascade attribute. If you don't specify a value for 'cascade' it defaults to 'none.' Cascade enables operations, like save, to cascade to the child entities that make up a collection.

_________________
Fred Stann
Solutions Architect


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 4:18 am 
Newbie

Joined: Wed Aug 22, 2007 11:00 am
Posts: 3
Hi Fred and thanks for the quick response!

Yeah I tried setting the cascade attribute to "all" and no joy. I've also tried using bag instead of set and an arraylist instead of an integer array and again no joy. And now im getting invalid cast exception when trying to save the class to the database.
Im stumped on this one.

Cheers
Ian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 10:10 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
You shouldn't have a collection of integers in your setType, instead a collection of the instruments themselves. Could you post your code, both for the class and how you are saving/retrieving?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 10:16 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
_.


Last edited by marcal on Thu Aug 23, 2007 10:29 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 10:20 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
_.


Last edited by marcal on Thu Aug 23, 2007 10:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 10:27 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
sorry about the multiples.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 11:04 am 
Newbie

Joined: Wed Aug 22, 2007 11:00 am
Posts: 3
But is populating possibly hundreds of objects with all their information not a bit overkill when all i need is the name and its id?
I finally got it working using the following mapping and by adding a counter column to the db and class. its a bit weird that you have to do that but it's as per the nhibernate documentation

Code:
<primitive-array name="instrumentIDs" table="setTypeInstrument">
      <key column="setTypeID"/>
      <index column="counter"/>
      <element column="instrumentID" type="Int32"/>
      </primitive-array>


thanks for the help lads
Ian


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