[jboss-user] [EJB 3.0] - ManyToMany Relationship

deano do-not-reply at jboss.com
Wed Dec 13 18:34:37 EST 2006


Hey guys,

We have a scenario where our manytomany table is not simply two foreign id's. basically we have an entity that has (many) relationships to itself. 

ie an ITEM object may have many associated ITEM, defined by relationship_type

so (* is PK, ^ is FK)

ITEM(id*, name ...)

ITEM_RELATIONSHIP(fromItemID*^, toItemID*^, relationship_type*)

so for any item, we can have many related items, and each related item has a relationship_type(ie. child, sibling etc)

So the following will return all items related, and i want to return only those with relationship_type = 'CHILD'

@ManyToMany(cascade = CascadeType.ALL, 
  |             fetch = FetchType.LAZY)
  |     @JoinTable(name = "item_relationship",
  |     		inverseJoinColumns = {@JoinColumn(name = "toItemId")},
  |     		joinColumns = {@JoinColumn(name = "fromItemId")})
  | getChildRelationships()


hope it makes sense :) any ideas?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993626#3993626

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993626



More information about the jboss-user mailing list