Reputation: 397
This is a follow-up question based on Oliver Gierke's suggestion.
We have two tables (almost same information) but for some external reasons, cannot use a common single table. I am getting an error that the base class is not a mapped entity. Oliver Gierke has mentioned in his response that it would work only for Single Table. I am assuming that is the reason. if so, could someone explain why such limitation and how can I make the following work.
Base entity:
@MappedSuperclass
public abstract class DecisionEntity {
Inherited classes:
@Entity
@Table(name="DM_INSP_TASKING_RULES_RSLT")
public class DmInspTaskingRulesRslt extends DecisionEntity implements Serializable {
@Entity
@Table(name="DM_UW_REF_RULES_RSLT")
public class DmUwRefRulesRslt extends DecisionEntity implements Serializable {
The Repository
@Repository
public interface DecisionManagementRepository<T extends DecisionEntity> extends JpaRepository<DecisionEntity, Long> {
Have defined 'packagesToScan' and also listed all the 3 classes in persistence.xml. I am getting the 'Non an Managed Entity' for 'DecisionEntity' class. I tried Inheritence Type - 'TABLE_PER_CLASS
Upvotes: 0
Views: 1292
Reputation: 31567
This is not supported by Spring Data JPA and Java Persistance API Specification.
Spring Data JPA Issue DATAJPA-264
Repositories: throw exception at startup if entity is a not an @Entity (e.g. for @MappedSuperclass)
Status: Investigating
Resolution: Unresolved
The JPA specifications says:
A mapped superclass, unlike an entity, is not queryable and must not be passed as an argument to
EntityManager
orQuery
operations. Persistent relationships defined by a mapped superclass must be unidirectional.
Upvotes: 1