-->
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.  [ 7 posts ] 
Author Message
 Post subject: mapping question
PostPosted: Fri Apr 02, 2004 3:11 am 
Newbie

Joined: Tue Mar 30, 2004 4:02 am
Posts: 3
Hi,

I have a class that consists of a one-to-one mapping class and a one-to-many mapping class. No own table is required for that class. So this class doesn't require a key column by its own, but can use a key-property of the mapped (one-to-one) class.

My question is how I can express this in my associated *.hbm.xml-File. Do I have to use a composite-id? (But it's only one key- property needed) Is it possible to use the <id> tag with a costum type?

Using Hibernate 2.

Thanks for help,
Joerg


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really get you. Does component or collection of value does what you need ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 2:38 pm 
Newbie

Joined: Tue Mar 30, 2004 4:02 am
Posts: 3
My class A look like this:
Code:
public class A {
   B myB;
                Map myC;

        ...
}


No other variables are required. B and C are hibernate mapped classes. A doesn't require its own table. What I'm searching for is a mapping for A like this:

Code:
<hibernate-mapping package="client.test">
      <class name="A" >
        <one-to-one name="myB" class="B"/>
        <map name="myC" table="tableC" cascade="all" inverse="true">
         <key column="c_id"/>
         <index column="date" type="date"/>
         <one-to-many class="C"/>
      </map>
   </class>
</hibernate-mapping>



What I need is an <id> for A. This identifier should be the same as the Identifier of class B. Is there a way to map that id?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 3:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Kind of
use <id> with foreign generator and <one-to-one constrained="true"/>
check the doc for appropriate details

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 2:40 am 
Newbie

Joined: Tue Mar 30, 2004 4:02 am
Posts: 3
Emmanuel, thanks for your support.
Is it necessary to declare a variable id for A? In my modell it would be better to use the identifier of class B in a way such as A.B.id instead of A.id. Your proposal means to map the values of A.B.id to A.id, is this correct? Is there a way to avoid A.id?

Joerg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No there is no way to avoid a.id (you can set it as private however)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats not entirely correct, you need an <id> mapping for every entity (value/component mappings of course don't), but not an identifier property (not even a private) in your persistent classes. Detached objects won't work without, however.

_________________
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.  [ 7 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.