-->
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: HELP! Can't get creating a many-to-many relation to work
PostPosted: Mon Mar 21, 2005 4:37 pm 
Newbie

Joined: Tue Mar 08, 2005 5:32 pm
Posts: 11
I really would apreciate if somebody could help me to solve this. I have a many-to-many relation between two classes, Category and Content. The mapping look like this on Category side:

<set
name="content"
table="CATEGORIES2CONTENT"
order-by="CONTENT_FK"
fetch="select"
lazy="true"
inverse="false"
cascade="save-update"
>
<key>
<column name="CATEGORIES_FK"/>
</key>
<many-to-many
class="com.abrahamsson.portal.content.ContentImpl"
entity-name="Content"
column="CONTENT_FK"
/>
</set>

and on Content side:

<set
name="categories"
table="CATEGORIES2CONTENT"
order-by="CATEGORIES_FK"
fetch="select"
lazy="true"
inverse="true"
>
<key>
<column name="CONTENT_FK"/>
</key>
<many-to-many
class="com.abrahamsson.portal.content.CategoryImpl"
entity-name="Category"
column="CATEGORIES_FK"
/>
</set>

I've tried with and without cascade.

In the client I have a detached Category object to which I add a newly created Content object. The code looks like this:

if(content.getCategories() == null) {
content.setCategories(new HashSet());
}
content.getCategories().add(category);
category.getContent().add(content);

service().updateCategory(category);

updateCategory is a method on a Session bean which essencially do session.saveOrUpdate(category);

What happen is that Content is persisted but no matter how I try I can't get it to put any record in the CATEGORIES2CONTENT table, hence no relation.

I've tested many variants of this as well, e.g. first send the transient Content object to the service to get a detached object back, then set the relation and updating again but no change.

This worked fine with Hibernate 2 but something got broken in Hibernate3.

I've tried to trace it but haven't had much luck so far since the internal works of Hibernate is a bit hard to get into. I see that it pass org.hibernate.event.def.OnUpdateVisitor which contain this part:

// null or brand new collection
// this will also (inefficiently) handle arrays, which have
// no snapshot, so we can't do any better
removeCollection(persister, key, session);
//processArrayOrNewCollection(collection, type);

on the other hand it also pass org.hibernate.event.def.WrapVisitor which contain the method processArrayOrNewCollection but that doesn't help..

I'm stuck on this :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 6:32 pm 
Newbie

Joined: Tue Mar 08, 2005 5:32 pm
Posts: 11
Some updates. After adding a session.flush() I get things to happen. My session beans are generated by AndroMDA 3.0RC1 and it just close the session so does that mean that I have to add an explicit call to session.flush() ? (the correct answer is to implement support for transactions, I will look into that).

I am getting other exceptions now which I'll investigate further.


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.