-->
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: idbag collection mapping - surrogate key question
PostPosted: Fri Mar 02, 2007 3:00 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
On page 254 of JPWH is an example of a collection mapped as an
<idbag> with a surrogate key declared as a <collection-id>.

My question has to do with the definition of the Java class corresponding
to the <composite-element> class. Does the Java class contain a property
for the collection-id (in the example "ITEM_IMAGE_ID")?

If not, does that mean that the Java class cannot (should not?) be aware
of its surrogate key, and the surrogate key is not retrievable in Java?

The reason for this question is that I implemented this pattern with
getter/setter methods for the surrogate key in the Java class, but
the setter method is not being called when Hibernate loads the collection
from the database. The debug log shows that the column is being
fetched but its value is not being placed into the Java object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 3:18 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
I tried just adding the column to the composite-element. See below,
the "PROJECT_ID" column inside the <composite-element> tag inside
the <idbag> tag.

Unfortunately, Hibernate doesn't like the fact that the PROJECT_ID
column is now mapped twice, once as the collection-id, and once as
an attribute. The exception is

org.hibernate.MappingException: Repeated column in mapping for collection: com.wholefoods.ittoolkit.ws.admin.Team.projects column: PROJECT_ID

I tried adding a 'name=' attribute to the <collection-id> but that is
not allowed by the DTD.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.wholefoods.ittoolkit.ws.admin">
  <class name="Team" table="CR_TEAM">
     <id name="id" column="TEAM_ID">
        <generator class="sequence">
           <param name="sequence">CR_TEAM_ID</param>
        </generator>
     </id>
     <property name="version" column="VERSION"/>
     <property name="name" column="NAME"/>
     <property name="email" column="EMAIL"/>
     <property name="remedyGroupId" column="RMDY_GROUP_ID"/>
     
     <set name="members" table="CR_TEAM_MEMBER">
        <key column="TEAM_ID"/>
        <composite-element class="TeamMember">
           <property name="name"   column="NAME"    not-null="true"/>
           <property name="email"  column="EMAIL"   not-null="true"/>
           <property name="userId" column="USER_ID" not-null="true"/>
           <property name="roleId" column="ROLE_ID" not-null="true"/>
        </composite-element>
     </set>

     <idbag name="projects" table="CR_PROJECT" order-by="NAME asc">
        <collection-id type="long" column="PROJECT_ID">
           <generator class="sequence">
              <param name="sequence">CR_PROJECT_ID</param>
         </generator>
      </collection-id>
      
        <key column="TEAM_ID"/>
        
        <composite-element class="TeamProject">
           <property name="id"     column="PROJECT_ID"/>
           <property name="name"   column="NAME"    not-null="true"/>
        </composite-element>
     </idbag>
     
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
formula="repeatedcolumn"

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.