Hibernate is mapped to superclass relationships and overrides

I have an abstract MappedSuperClass Member, which is extended by three types of Member. Each of them then uses its own "Project", as well as the abstract MappedSuperClass. However, I want the base class to know about projects, so I can write general code to interact with the participants. How to specify this using Hibernate annotations? and how do I redefine it in the ExtendedParticipant and ExtendedProject classes?

Each type of participant and each type of project has its own database tables with existing data and identifiers (not unique to tables) that I cannot change.

The following code gives me an IDE error. "The set to one attribute should not be" Mapped Superclass ".

@MappedSuperclass public abstract class Participant implements Persistable { ... @ManyToOne @JoinColumn(name = "project_id") public Project getProject() { return project; } public void setProject(Project project) { this.project = project; } ... } 

and the Project class is similar to the same problem:

 @MappedSuperclass public abstract class Project implements Persistable { ... @OneToMany public List<Participant> getParticipants() { return participants; } public void setProject(List<Participant> participants) { this.participants = participants; } ... } 
+7
java annotations hibernate
source share
2 answers

The mapped superclass is not an entity; it cannot be part of an association. So, map your classes as entities and either represent the mapped superclass "above" or use the TABLE_PER_CLASS strategy.

see also

  • EclipseLink: MappedSuperclass request not working
  • Hibernate - persistent polymorphic compounds
+5
source share

It seems possible to have relationships defined through mappedsuperclass according to the following

0
source share

All Articles