0

We have a requirement to persist into separate tables history records for our entities. I looked into Envers but the REVINFO table is a problem for retrofitting existing customers and performance.

I was thinking of an approach where we have each or our "concrete" entites (say CUSTOMER) annotated with @MappedSuperclass ....data would be saved to the CUSTOMER table. We would entity subclass Customer class called "CustomerHistory" and add the fields we need (historyId (primary key), start time, end time) that would be persisted to the CUSTOMER_ADDRESS table.

Would this work? With JPA handle the primary key in 2 tables?

Thanks.

Mike Rother
  • 591
  • 4
  • 16

1 Answers1

0

In case anyone else is thinking about this...It appears to be not a valid option. Here is the stack trace I received.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.mapping.SingleTableSubclass cannot be cast to org.hibernate.mapping.RootClass

Mike Rother
  • 591
  • 4
  • 16