Hibernate ManyToMany and superclass mapping problem

Posted by Jesus Benito on Stack Overflow See other posts from Stack Overflow or by Jesus Benito
Published on 2010-05-27T16:41:47Z Indexed on 2010/05/27 17:01 UTC
Read the original article Hit count: 353

Filed under:
|
|

Hi all,

I need to create a relation in Hibernate, linking three tables: Survey, User and Group. The Survey can be visible to a User or to a Group, and a Group is form of several Users.

My idea was to create a superclass for User and Group, and create a ManyToMany relationship between that superclass and Survey.

My problem is that Group, is not map to a table, but to a view, so I can't split the fields of Group among several tables -which would happen if I created a common superclass-.

I thought about creating a common interface, but mapping to them is not allowed. I will probably end up going for a two relations solution (Survey-User and Survey-Group), but I don't like too much that approach.

I thought as well about creating a table that would look like:

  Survey Id  |  ElementId  | Type

ElementId would be the Group or UserId, and the type... the type of it. Does anyone know how to achieve it using hibernate annotations? Any other ideas?

Thanks a lot

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate