-->
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.  [ 7 posts ] 
Author Message
 Post subject: Many-to-Many with attributes to assoc. Need cascade delete
PostPosted: Wed May 25, 2005 11:10 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi all,

I have a case as follows:

Table A and table B have many-to-many relationship. The association table AB has (extra) nullable attributes. I tried to use "composite-element" as follows:

AB is modelled as a composite element in A. AB has reference to B.

Now if I delete an entry of AB from A, corresponding entry from table B is not deleted. The cascade="all" option doesn't work in this case.

What could be the reason?
Also can u suggest any other way to model this relationship?

Thanks in advance
-Reshma





Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b]

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 11:24 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
You dont need such modeling, many-to- many is handled in database.
You need A object, B object and AB table where A's id and B's id are foreign keys. Then just map as simple <many-to-many> mapping with cascade property.

_________________
-developer


Top
 Profile  
 
 Post subject: can't do that, my association table has nullable attributes
PostPosted: Thu May 26, 2005 12:55 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi,

Thanks for your reply.

As i mentioned in my first post, i have a case where my "association table has nullable attributes". "many-to-many" relationship doesn't support that.

This case is handled by "composite-element". But it dosen't permit cascade delete operation as a component is of "value-type".

So i cannot use composite-element either.

can you think of some other way to model this relationship.
Please reply As soon as possible ... (have a deadline to meet :-) )


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 2:47 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi,

my problem is solved. It worked successfully with a combination of
A AB A
one-to-many many-to-one

and lifecycle methods.
Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 4:34 am 
Newbie

Joined: Tue Sep 09, 2003 3:37 am
Posts: 4
Hi Reshma,
I have your same problem.
Can you post the part of the mapping you used for this?

I have 3 tables, and the association table has one attribute.

I'd like to map this with just 2 classes: one main class with a collection of elements whose data is taken from a "join" of the association table and the last table.

Thanks for any suggestion.

Bye

Lorenzo


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 5:18 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi Lorenzo,

In this case if you want to have just 2 files, then you will have to use composite-element tag. But it has some disadvantages
1. Your mapping table cannot have nullable attributes else hibernate fails.
2. If you want cascade delete effect, this cannot be achieved. I tried only
insert case and it worked with it. But delete didn't work (since
composite-element is of value type).

mapping file of 1st class,

<composite-element class="(name of association class)">
<property name="attribute1" />
<many-to-one (entry for 2nd class)>
....
....
</many-to-one>
<composite-element>

The association table won't have mapping file but will have a java class. That class should have object of 2nd class and additional attributes if any.

Reference:
http://docs.jboss.org/ejb3/Hibernate3/r ... ml_single/
8.2. Collections of dependent objects

hope this answers your question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 5:46 am 
Newbie

Joined: Tue Sep 09, 2003 3:37 am
Posts: 4
Thank you for your prompt reply, I'll try as soon as possible...maybe on monday ;)


Ciao

Lorenzo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.