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 :(
|