-->
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 with extra column performance issue.
PostPosted: Wed Jun 30, 2004 5:40 am 
Newbie

Joined: Wed May 05, 2004 9:48 am
Posts: 8
Hi,

I have class Document which has many-to-many back to Document. But this association table has extra column.

The main class looks like:

public class Document
{
private Long id;
private String name;
private Set parent = new HashSet();
private Set child = new HashSet();

... setters/getters
}


The association class is:
public class DocumentRel
{
private Document parent;
private Document child;
private String color;

... setters/getters
}

mapping is:

<class name="Document" table="doctest">

<id name="id" type="long" unsaved-value="null" >
<generator class="sequence">
<param name="sequence">doc_sequence</param>
</generator>
</id>

<property name="name"/>

<set name="parent" inverse="false" lazy="false" table="doctest_rel">
<key column="child_id"/>
<composite-element class="DocumentRel">
<property name="color"/>
<many-to-one name="parent" column="parent_id" class="Document" />
</composite-element>
</set>

</class>


The code is:


DocumentRel rel = new DocumentRel();
rel.setColor( "a" );
rel.setParent( doc2 );
doc1.getParent().add( rel );

session.save( doc2 );
session.save( doc1 );

The result is:

insert into doctest (name, id) values (?, ?)
insert into doctest_rel (child_id, color, parent) values (?, ?, ?)
delete from doctest_rel where child_id=? and color=? and parent=?
insert into doctest_rel (child_id, color, parent) values (?, ?, ?)

why is there inser, delete and again insert into relation table ? Why its not there only one insert ?

any help would be appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 11:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
The code is:


DocumentRel rel = new DocumentRel();
rel.setColor( "a" );
rel.setParent( doc2 );
doc1.getParent().add( rel );

session.save( doc2 );
session.save( doc1 );


This cannot be all the code. How do you get the references to doc1 and doc2? For you benefit (as well as ours in trying to help you) I suggest you come up with a simple main() that tries the use case where you are seeing this issue.


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.