-->
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.  [ 4 posts ] 
Author Message
 Post subject: bidirectional association between component and entity
PostPosted: Tue Jun 06, 2006 12:47 pm 
Newbie

Joined: Thu Feb 16, 2006 2:05 pm
Posts: 10
Location: Nürnberg, Germany
Hibernate version:
3.1.2

Mapping documents:
Code:

<hibernate-mapping package="component">
   <class name="EntityA" table="ENTITYA">
   
      <id name="id" column="ID" type="long">
         <generator class="increment"/>
      </id>
         
      <component name="myComponent" class="ComponentA" >
         
         <parent name="myEntity"/>
         
         <property name="title" column="TITLE" type="string"/>
         
         <set name="entityBs">
            <key column="A_ID"></key>
            <one-to-many class="EntityB"></one-to-many>
         </set>
         
      </component>
      
   </class>
</hibernate-mapping>



I'm trying to map a bidirectional association between a component of type "ComponentA" -which is part of an entity of type "EntityA" - to an entity of type "EntityB". The unidirectional association from above works, but I couldn't figure out how the mapping for the many-to-one-element on the other side would have to look like.

I tried this...

Code:
<hibernate-mapping package="component">
   
   <class name="EntityB" table="ENTITYB">
   
      <id name="id" column="ID" type="long">
         <generator class="increment"/>
      </id>

      <many-to-one name="component" class="ComponentA" column="A_ID">
      </many-to-one>

   </class>
</hibernate-mapping>


... and got an error like this from hbm2ddl:

An association from the table ENTITYB refers to an unmapped class: component.ComponentA

The same happens, if I omit the class-attribute.

Is there a way to get this kind of association work?

Thanx in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 7:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No. Components are values, not entities, and thus cannot be the "target" of an association like this. Change your component to a proper mapped entity to do this.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 4:44 am 
Newbie

Joined: Thu Feb 16, 2006 2:05 pm
Posts: 10
Location: Nürnberg, Germany
Thanx, for answering.

I can stop my experiments with this kind of association now...

I thought I would have the freedom to decide, if two java-classes with a one-to-one association use a common database table (component-mapping) or use two database tables (<one-to-one>mapping with two entities).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 5:13 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
We do. The decision is whether or not you want
  1. an entity, that can be stand-alone or be referred to from any other entity, or
  2. a value, that has no life of its own and is 100% dependent on the entity that wraps it.

_________________
Code tags are your friend. Know them and use them.


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