I'm running a Spring Boot app.
I have these two tables in my database. I fill an example of data that contains these tables.
Table user
Here columns id and century are PKs, and column state_id is a FK from table state with a reference of column id and century is also a FK from table state. So the century column is a FK and a PK at the same time.
| id | century | name | state_id |
|---|---|---|---|
| 33 | 21 | John Doe | 1 |
Table state
Here, columns id and century are both primary keys of the table
| id | century | label |
|---|---|---|
| 1 | 21 | cold |
I want to model these two tables as JPA entities, so I did it like this:
StatePK.java:
@Embeddable
public class StatePK implements Serializable {
private Long id;
private Integer century;
}
State.java:
@Entity
@Table(name = "state")
public class State {
@EmbeddedId
private StatePK id;
private String label;
}
UserPK.java:
@Embeddable
public class UserPK implements Serializable {
private Long id;
private Integer century;
}
User.java:
@Entity
@Table(name = "user")
public class User implements Serializable {
@EmbeddedId
private UserPK id;
private String name;
@MapsId("century")
@ManyToOne(optional = false)
@JoinColumns(value = {
@JoinColumn(name = "century", referencedColumnName = "century"),
@JoinColumn(name = "state_id", referencedColumnName = "id")})
private State state;
}
When I launch the application, I have the following error:
Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalStateException: PostInitCallback queue could not be processed...\r\n - PostInitCallbackEntry - EmbeddableMappingType(fr.xxx.User#{id})#finishInitialization
How can I resolve this error?