-->
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: Two properties of same class
PostPosted: Wed Dec 21, 2005 4:57 pm 
Newbie

Joined: Wed Dec 21, 2005 3:47 pm
Posts: 1
Hello

I have a case where we have the following scenario:

class A {
private ClassB b1;
private ClassB b2;
}

I have given the setters property many-to-one.

When I changed to
class A {
private Set bs;
}

and given the relation property many-to-many
It seems to work better, but is it possible to get the first case to work and if so how? And if one cant make it work why?


Top
 Profile  
 
 Post subject: works
PostPosted: Wed Dec 21, 2005 6:04 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Seems to work fine:
Session s = getSessions().openSession();
Classb b1 = new Classb("b1");
Classb b2 = new Classb("b2");
Classa a = new Classa();
a.setP1( b1 );
a.setP2( b2);
Transaction t = s.beginTransaction();
s.save( a );
t.commit();
s.close();

The mapping:
Code:
<hibernate-mapping
   package="org.hibernate.test.kgi">

   <class name="Classa" table="`classes_a`" >

        <id name="id" unsaved-value="null">
           <generator class="native"/>
        </id>

        <many-to-one name="p1" class="Classb" cascade="all"/>
        <many-to-one name="p2" class="Classb"  cascade="all"/>
    </class>

    <class name="Classb" table="`classes_b`">

            <id name="id"  unsaved-value="null">
               <generator class="native"/>
            </id>

        <property name="name"/>
        </class>

</hibernate-mapping>


_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.