-->
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: many-to-many inverse parameter usage
PostPosted: Mon Mar 28, 2005 2:18 pm 
Newbie

Joined: Sun Nov 07, 2004 7:03 am
Posts: 8
I've read in Hibernate docs that using inverse="true" on the one side of many-to-many relationship and inverse="false" on the other prevents from inserting two identical rows to relationship table. I've wrote a test application just to get on with it and, to my surprise, I got two inserts instead one. Could anybody explain this? Thnx in advance...

Association mappings are as follows:

<set name="applications" inverse="true" table="hb_application_developers">
<key column="developer_id"/>
<many-to-many column="application_id" class="pl.test.ApplicationHb"/>
</set>

on the one side and:

<set name="developers" inverse="false" table="hb_application_developers">
<key column="application_id"/>
<many-to-many column="developer_id" class="pl.test.DeveloperHb"/>
</set>

on the other. The code does above:

Session session = HibernateUtil.getSession(); //obtains session from SessionFactory
Transaction tx = session.beginTransaction();

ApplicationHb application = new ApplicationHb("XyberMech");
DeveloperHb developer = new DeveloperHb("A.Solecki");

session.save(application);
session.save(developer);

session.flush();

application.getDevelopers().add(developer);
developer.getApplications().add(application);

session.update(application);

HibernateUtil.closeSession(session, tx);//commits transaction and closes session

And the result SQL is:

select nextval ('hibernate_sequence')
select nextval ('hibernate_sequence')
insert into hb_application (title, id) values ('XyberMech', 546555)
insert into hb_developer (name, id) values ('A.Solecki', 546556)
insert into hb_application_developers (application_id, developer_id) values (546555, 546556)
insert into hb_application_developers (developer_id, application_id) values (546556, 546555)

On the other hand, when I set both sides to inverse=false or both sides to inverse="true", everything works fine o_O.
I use Hibernate 3.0 and Postgres 7.4 .


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 4:07 pm 
Newbie

Joined: Sun Nov 07, 2004 7:03 am
Posts: 8
I had to have a total eclipse of my mind when I was writing previous post. Everything works fine now, with inverse="true" on one side and inverse="false" on the other.

-------------------------------------------------------

Theory: When nothing works, but you know what's wrong
Practice: When everything works fine, but you have no idea why
I mix those two approaches: Nothing works and I have no idea why


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.