I am using Spring Boot 1.3 with Spring Data JPA. I have want to use early primary key generation using a dedicated object for the primary key (As advised in Implementing Domain Driven Design).
Suppose this entity:
@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 this works fine. However, I want to create a superclass for all id classes, something like:
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 now when I run my application there is the following exception:
org.hibernate.AnnotationException: BookId has no persistent id property: Book.id
Why does that suddenly not work anymore?
Put @MappedSuperclass
on EntityUuidId
class, that way its properties will be treated as persistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With