-->
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.  [ 2 posts ] 
Author Message
 Post subject: Complex Mapping issue
PostPosted: Fri Apr 13, 2007 4:11 am 
Newbie

Joined: Wed Oct 25, 2006 2:12 pm
Posts: 6
Hibernate version: 3
Mapping documents: N/A
Code between sessionFactory.openSession() and session.close(): N/A
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: Any
The generated SQL (show_sql=true): N/A
Debug level Hibernate log excerpt: N/A


Hi,

I am trying to achieve something quite specific in a mapping but don't manage to do it...

I have 2 tables, ASSEMBLY_MASTER and ASSEMBLY_ITERATION.
I want to extract a single entity : Assembly from both Tables.
The hard point comes from the fact that the ASSEMBLY_MASTER row will be shared by several rows in the ASSEMBLY_ITERATION.

ASSEMBLY_MASTER have a generated Id as PK
ASSEMBLY_ITERATION uses a composite key based on the ASSEMBLY_MASTER ID and on a version number.

I ended up with the following mapping:

<hibernate-mapping package="cimpa.design2x.domain.model.to">
<class name="Assembly" table="ASSEMBLY_MASTER">
<id name="id" column="ASSEMBLY_ID">
<generator class="native"></generator>
</id>
<property name="name" column="NAME" type="string"></property>
<join table="ASSEMBLY_ITERATION">
<key>
<column name="ASSEMBLY_ID"></column>
</key>
<composite-id>
<column name="ASSEMBLY_ID"></column>
<column name="VERSION"></column>
</composite-id>
<property name="version" type="long" column="VERSION"></property>
</join>
</class>
</hibernate-mapping>

Surely this mapping is not valid but it represents well what I'm trying to achieve.

The target is to be able to retrieve a given version of an Assembly entity and to be able to create a new version of the assembly while altering the field held by the already existing master part...


Thanks for any help...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 9:21 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
1st, you're posting a non-annotations-related question to wrong forum :) But you're mapping is very close to what you need. One thing you need to keep in mind that Hibernate does not need to emulate exactly what the database does. Just because the database defines a composite PK, doesn't mean your Object model needs one as well.

Since you can't have 2 IDs in a mapping file, as that is invalid, you obviously need to make sure those values are stored when you create or update the entity. You can however treat VERSION column a non-null property of your entity, even though the database sees it as part of the PK on the ASSEMBLY_ITERATION table. The mapping for ASSEMBLY_ID is already there due to the <key> element on the <join>. If you do that, it should work.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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