-->
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.  [ 1 post ] 
Author Message
 Post subject: Multiple @ManyToMany sets from one join table
PostPosted: Thu Nov 19, 2009 6:20 am 
Newbie

Joined: Thu Nov 19, 2009 6:13 am
Posts: 3
Hi guys,

I'm mapping a proprietary database to Hibernate for use with Spring. In it, there are a couple of jointables that, for entity A and entity B have the following schema:

Code:
    CREATE TABLE AjoinB (
      idA int not null,
      idB int not null,
      groupEnum enum ('groupC', 'groupD', 'groupE'),
      primary key(idA, idB, groupEnum)
    );


As you can see, this indicates that there can be multiple A-B relationships that put them in different groups. I'd like to end up with, first line for entity A and second for entity B, the following sets

Code:
    Set<B> BforGroupC, BforGroupD, BforGroupE;
    Set<A> AforGroupC, AforGroupD, AforGroupE;


So far, I've only managed to put them in one set and disregard the groupEnum relationship attribute:

Code:
    @ManyToMany(targetEntity=B.class, cascade={ CascadeType.PERSIST, CascadeType.MERGE } )
    @JoinTable(name="AjoinB", joinColumns=@JoinColumn(name="idA"), inverseJoinColumns=@JoinColumn(name="idB") )
    private Set<B> BforAllGroups;


and

Code:
    @ManyToMany( mappedBy = "BforAllGroups", targetEntity = A.class )
    private Set<A> AforAllGroups;


How can I make multiple sets where they belong either in groupC, groupD or groupE?

Doing something like

Code:
    @Discriminator(name="groupEnum", value="groupC", discriminatorType=ENUM, enumerated=EnumType.STRING)
    @ManyToMany(targetEntity=B.class, cascade={ CascadeType.PERSIST, CascadeType.MERGE } )
    @JoinTable(name="AjoinB", joinColumns=@JoinColumn(name="idA"), inverseJoinColumns=@JoinColumn(name="idB") )
    private Set<B> BforGroupC;


would be beautiful :-)

Cheers

Nik


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.