0

I am trying to utilise Spring JPA inheritance for my entities. Below are the code snippets of the annotations that I use for the classes. The application is based on Spring Boot v2.2.2.RELEASE.

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "entityType", discriminatorType = DiscriminatorType.STRING)
@Getter
@Setter
@NoArgsConstructor
public class RmlAction extends RmlBase {
//attributes
}

Sub-classes: RmlEfsAction.java

@Entity
@Getter
@Setter
@DiscriminatorValue("EFS")
@Table(name = "rml_actions")
@DiscriminatorColumn(name = "entityType", discriminatorType = DiscriminatorType.STRING)
@NoArgsConstructor
public class RmlEfsAction extends RmlAction {
//no attribute
//only constructor
}

RmlProjectAction.java

@Entity
@Getter
@Setter
@DiscriminatorValue("PROJECT")
@Table(name = "rml_actions")
@DiscriminatorColumn(name = "entityType", discriminatorType = DiscriminatorType.STRING)
@NoArgsConstructor
public class RmlProjectAction extends RmlAction {
//no attribute
//only constructor
}

The server starts fine but when I try to do a Data entry, it gives the below error during getting an entity for RmlEfsAction. Any help in identifying the issue is appreciated.

Caused by: org.hibernate.DuplicateMappingException: Duplicate table mapping rml_actions
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addDenormalizedTable(InFlightMetadataCollectorImpl.java:758)
    at org.hibernate.cfg.annotations.TableBinder.buildAndFillTable(TableBinder.java:499)
    at org.hibernate.cfg.annotations.EntityBinder.bindTable(EntityBinder.java:670)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:603)

Code for fetching entity:

RmlEfsAction dbAction = (RmlEfsAction) actionRepository.getOne(rmlAction.getId());
The Cloud Guy
  • 963
  • 1
  • 8
  • 20

0 Answers0