-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with composite-element and composite id when used to
PostPosted: Wed May 26, 2004 3:13 pm 
Newbie

Joined: Wed May 26, 2004 2:58 pm
Posts: 1
Hi all
I have a class A which contains a list of elements of type B. I've mapped this relationship as a composite-element collection. This works fine for saving a transient instance of A (and its related B's). The problem is when I load an instance of A its list of B elements is empty. If the id of A is a single column this mapping works OK and load() returns the child elements (B) along with A.
Does anybody know which is the problem?
Thanks

I'm using Hibernate 2.1.2 and Postgres 7.4.2

Here are my POJOS and mappings:

Code:
package test;

import java.util.Collections;
import java.util.List;

/**
* @hibernate.class table="TABLE_A"
*/
public class A {
   private AId id = null;
   private List elements = Collections.EMPTY_LIST;
   
   /**
    * @hibernate.id generator-class="test.AId"
    */
   public AId getId() {
      return id;
   }

   /**
    * @param id
    */
   public void setId(AId id) {
      this.id = id;
   }

   /**
    * @hibernate.list cascade="all"
    * @hibernate.collection-composite-element class="test.B"
    * @hibernate.collection-index column="INDEX"
    * @hibernate.collection-key
    * @hibernate.collection-key-column name="A1"
    * @hibernate.collection-key-column name="A2"
    */
   public List getElements() {
      return elements;
   }

   /**
    * @param elements
    */
   public void setElements(List elements) {
      this.elements = elements;
   }
}

package test;

public class B {
   private String name = null;

   public B() {
   }

   public B(String name) {
      this.name = name;
   }

   /**
    * @hibernate.property column="NAME"
    */
   public String getName() {
      return name;
   }

   /**
    * @param name
    */
   public void setName(String name) {
      this.name = name;
   }
}


<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="test.A"
table="TABLE_A"
dynamic-update="false"
dynamic-insert="false">

<composite-id
name="id"
class="test.AId">
<key-property
name="a1"
type="java.lang.String"
column="A1"/>

<key-property
name="a2"
type="java.lang.String"
column="A2"/>
</composite-id>

<list
name="elements"
lazy="false"
inverse="false"
cascade="all"
>

<key>
<column name="A1" />
<column name="A2" />
</key>

<index
column="INDEX"
/>

<composite-element
class="test.B">

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAME"
/>

</composite-element>

</list>
</class>
</hibernate-mapping>

[/list]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.