users@glassfish.java.net

Inheritance, join table and relations...

From: <glassfish_at_javadesktop.org>
Date: Tue, 13 May 2008 03:41:49 PDT

Hi, would the following be possible with jpa?

Two tables with a join table and many to many relationship. One of the tables is mapped as a normal entity and the other is mapped with inheritance single table strategy. We are only interested in mapping the many to many relation with the normal entity and one of the entities that is a sub class in the inheritance structure of the other mapped table. The join table, however, can include mappings between rows that are not just the specific sub class of the table mapped with inheritance.

It does not seem to work so our alternative is probably to map the relation to the super class or create another join table. (It does actually work in one direction but that is kind of obvious why it would.)

Ex:

@Entity
public class AnEntity {
@ManyToMany
Collection<ASub> subs;
...
}

@Entity
@Inheritance...
public abstract class ASuper {
...
}

@Entity
@DiscriminatorValue...
public class ASub extends ASuper {
@ManyToMany
@JoinTable...
Collection<AnEntity> entities;
...
}
[Message sent by forum member 'woel' (woel)]

http://forums.java.net/jive/thread.jspa?messageID=273985