-->
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: Problem on saving entity containing collection of components
PostPosted: Sat Jan 24, 2004 11:44 pm 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
Hello!

Suppose I have a many-to-many realtion between the two classes A and B. The association itself has an attribute, so I decide to model the association as an association-class C.

Now I decided to map this scenario with the approach recommended in the Hibernate Reference (chapter 7.2): "A special case of a composite element is a composite element with a nested <many-to-one> element. A mapping like this allows you to map extra columns of a many-to-many association table to the composite element class."

Here is my example mapping approach:

Code:
<class name="A" table="A">
    <id name="id" column="ID" />
        <generator class="uuid.string" />
    </id>
    <property name="some_property_A" />
</class>

<class name="B" table="B">
    <id name="id" column="ID" />
        <generator class="uuid.string" />
    </id>
    <property name="some_property_B" />
    <list name="listOfCs" table="LIST_OF_Cs">
        <key column="B_ID" />
        <index column="INDEX" />
        <composite-element class="C">
            <property name="some_property_C" />
            <many-to-one name="link_to_A" class="A" />
        </composite-element>
    </list>
</class>


So I have three classes A, B and C, where C is the only one, that has no "id"-attribute.
Now my question: do I need to declare a mapping for class "C"? Is it right, that I have 3 classes but only two mapping files (one for "A" and one for "B")?
"C" actually is my component-class. The class "C" has two attributes "some_property_C" and "link_to_A" with appropiate getters and setters.

The schema-export of this mapping works fine, the right tables are created, but I cannot save an entity of B, when I try to execute the following code (initialization of Configuration, Connection and SessionFactory are not shown in the code):

Code:
B b = new B();
b.setSome_Property_B("A String");
b.setListOfCs(new ArrayList());

sess.save(b);


An Exception is thrown, when trying to execute "sess.save(b)". Unfortunately the exception message does not show much information about what is going on, because my application throws a new Exception, when catching the HibernateException.

Another thing to be mentioned is that I use interfaces for the classes "A", "B" and "C" and my mapping actually is based on the mapping of interfaces. I just add the <subclass>-tag to declare the implementing classes of these interfaces.... but adding an interface layer is not the source of my problem I guess...

Thx in advance!

Philipp Hinnah


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 6:25 pm 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
Everything is okay now!

I discovered a little typing error in a setter :-)

Philipp


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.