-->
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: 1:n Assoc. change to collection of dep. objects
PostPosted: Mon Jun 14, 2004 2:46 am 
Newbie

Joined: Fri Jun 11, 2004 12:08 pm
Posts: 4
Hello,

currently I've got the following mapping from table 'Model' to 'FaceLift' (1:n bi-directional association):

[code]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.bosch.mds.types.vehicle.Model"
table="model"
>
<id name="id" type="long">
<generator class="native"></generator>
</id>
<set name="faceLifts" access="com.bosch.mds.hibernate.PropertyAccessor" cascade="all" inverse="true">
<key column="owner_id"/>
<one-to-many class="com.bosch.mds.types.vehicle.FaceLift"/>
</set>

<property name="name" type="string" access="com.bosch.mds.hibernate.PropertyAccessor"/>

</class>
</hibernate-mapping>
[/code]

and

[code]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="com.bosch.mds.types.vehicle.FaceLift"
table="face_lift"
>
<id name="id" type="long">
<generator class="native"></generator>
</id>
<property name="description" type="string" access="com.bosch.mds.hibernate.PropertyAccessor" />
<many-to-one column="owner_id" name="model" access="com.bosch.mds.hibernate.PropertyAccessor"
class="com.bosch.mds.types.vehicle.Model">
</many-to-one>
</class>
</hibernate-mapping>
[/code]

Now I'd like to change this so that 'FaceLift' becomes a collection of dependent objects within 'Model'.
I'Ve tried some approaches (i.e. only one mapping file for 'Model' containing:
<set name="faceLifts" table="face_lift" access="com.bosch.mds.hibernate.PropertyAccessor" >
<key column="id">
<composite-element class="com.bosch.mds.types.vehicle.FaceLift" >
<property name="description" type="string" access="com.bosch.mds.hibernate.PropertyAccessor" />

<property <many-to-one column="owner_id" name="model" access="com.bosch.mds.hibernate.PropertyAccessor"
class="com.bosch.mds.types.vehicle.Model">
</many-to-one>
</composite-element>
</set>

) retaining all properties of both tables. But I either receive that NULL can't be inserted in column 'owner_id' or 'id' of 'FaceLift'.
Can anybody tell me how a correct mapping could be? Thanks in advance.

Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:21 am 
Newbie

Joined: Fri Jun 11, 2004 12:08 pm
Posts: 4
Hello,

after further testing I don't use the 'id' from 'FaceLift' anymore and take the other properties as PrimaryKey. Now everything works fine.
Code:
<hibernate-mapping>
   <class
        name="Model"
        table="model"
    >
      <id name="id" type="long">
         <generator class="native"></generator>
      </id>

      <set name="faceLifts" table="face_lift" access="PropertyAccessor" >
         <key column="owner_id"/>
            <composite-element class="FaceLift">
            <property name="faceLiftDate" type="date" column="face_lift_date"  access="PropertyAccessor" />
            <property name="description" type="string" access="PropertyAccessor" />
           </composite-element>
      </set>
      <property name="name" type="string" access="PropertyAccessor"/>
    </class>
</hibernate-mapping>



Regards
Oliver


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.