-->
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.  [ 4 posts ] 
Author Message
 Post subject: M:M orphan in composite collection issue
PostPosted: Wed Jun 16, 2004 9:30 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
We have a requirement for a class which can have many children of the same type.

We map this composite-pattern type class as having a bag of children mapped as a many-to-many relationship:

Code:

<hibernate-mapping>
    <class
        name="com.foo.domain.Entity"
        table="entity_table"
        dynamic-update="false"
        dynamic-insert="false"
    >
    ...
        <bag
            name="children"
            table="parent_child_hierarchy"
            lazy="false"
            inverse="false"
            cascade="none"
        >

              <key
                  column="parent"
              />

              <many-to-many
                  class="com.foo.domain.Entity"
                  column="child"
                  outer-join="true"
              />

        </bag>
    ...
</hibernate-mapping>


However, unlike the composite pattern described in the wiki page, we do not have only single leafs, rather we can have many leaves of children. Thus, in our child class we do not have a M:1 relationship to the parent since it can potentially have many parents.

We handle the circular dependency issues in our business logic.

Question:

If we do a query on this type, for example:

Code:
from Entity as e where e.user= :userId


What is the most efficient way to return only "Enitity" classes which are not orphaned?

At one point we considered including a M:M relationship inside the entity that would contain a collection of parents. This would essentially be the same as the children mapping, except that it would key on the the child, rathen than the parent.

In that way we could have appended
Code:
where e.parents.size > 0


Any guidance would be appreciated.

Regards,
Roll


Top
 Profile  
 
 Post subject: Should add...
PostPosted: Wed Jun 16, 2004 9:37 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
I should add that we have a requirement to leave orphaned "Entity" classes around.

Also, we have attempted to map this many-to-many collection back to the parent previously with no success. There were failures during updates. If it makes sense, we'll certainly continue down this path.


Top
 Profile  
 
 Post subject: Any suggestions?
PostPosted: Thu Jun 17, 2004 9:57 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Any thoughts on this topic?

Certainly this has been addressed. We are familiar with the ref. docs and have scowered the forums. However, haven't come across this particular scenario in any of our use cases before.

Cheers,
Roll


Top
 Profile  
 
 Post subject: No suggestions?
PostPosted: Mon Jun 21, 2004 8:12 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
No suggestions?


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