An object does not have a constant id property when retrieving a superclass from the @EmbeddedId class

I am using Spring Boot 1.3 with Spring Data JPA. I want to use early primary key generation using a dedicated object for the primary key (as specified in Driven Driven Project Implementation ).

Suppose this object:

@Entity public class Book { @EmbeddedId private BookId id; } 

and this value object:

 @Embeddable public class BookId implements Serializable { private UUID id; protected BookId(){} //for hibernate public BookId( UUID id ) { this.id = id; } public UUID getId() { return id; } } 

Then it works great. However, I want to create a superclass for all id classes, for example:

 public class EntityUuidId implements Serializable { private UUID id; protected EntityUuidId(){} //for hibernate public EntityUuidId( UUID id ) { this.id = id; } public UUID getId() { return id; } } 

Now the BookId class changes to:

 @Embeddable public class BookId extends EntityUuidId { protected BookId(){} //for hibernate public BookId( UUID id ) { super(id); } } 

The problem is that when launching my application, the following exception exists:

 org.hibernate.AnnotationException: BookId has no persistent id property: Book.id 

Why doesn't it suddenly work?

+5
source share
1 answer

Put @MappedSuperclass in the EntityUuidId class, so its properties will be considered constant.

+6
source

Source: https://habr.com/ru/post/1238370/


All Articles