-->
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.  [ 1 post ] 
Author Message
 Post subject: Trouble inserting collection with Composite-Id
PostPosted: Mon Feb 06, 2006 2:26 pm 
Newbie

Joined: Mon Feb 06, 2006 2:03 pm
Posts: 2
Hi,

I have a 'Credential' table in my DB which is indexed by a composite Id of:
MemberId
CredentialTypeId

I have a 'Member' table, which has a foreign key reference to the Credential table, with it's MemberId column.

So, a member can have multiple Credentials. For example, for a Member with memberID=1000, we could have the following entries in the Credential table:

Member ID | Credential Type ID
--------------------------------------
1000 | 1
1000 | 2
1000 | 3

I am having trouble with my hibernate mappings when I create a new Member. I want the MemberID to be autogenerated for Member and for this MemberID to be set as the MemberID on the nested collection of Credentials. The Credential Type Id (the second id of the composite index) is set explicitly on each Credential object before saving. I can not set memberID explicitly as it is generated at save in the hibernate layer.

Here are my mappings:

MEMBER:

<class name="com.entity.Member" table="dbo.Member" lazy="false">
<id name="memberId">
<generator class="identity"/>
</id>
<bag name="credentials" table="dbo.MemberCredential">
<key column="memberID" />
<one-to-many class="com.entity.Credential"/>
</bag>
</class>


CREDENTIAL:

<class name="com.entity.Credential" table="dbo.MemberCredential" lazy="false">
<composite-id>
<key-property name="credentialTypeId" column="credentialTypeId"/>
<key-property name="memberId" column="memberId"/>
</composite-id>
<property name="username" column="Username"/>
<property name="password" column="Password"/>
</class>


I have played around with various settings. The mappings above seem the "closest" to correct but when I call saveOrUpdate(Member), the MemberID column of the nested array of Credential is null - not the auto generated MemberID that I am hoping for.

Am I referencing Credential correctly in Member? Do I need to explicitly tell it to use memberID? Have I mapped my Credential table correctly?

Any help would be much appreciated.

I am using hibernate 3.1, and JDK 1.4.2

Thanks!
James


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.