In my test project I'm trying to make work the following:
@Entity
@IdClass(PersonId.class)
public class Person {
@Id
private String name;
@Id
@ManyToOne
private Home home;
public class PersonId implements Serializable {
private String name;
private HomeId home;
@Entity
@IdClass(HomeId.class)
public class Home {
@Id
private String address;
@Id
private String bed;
@OneToMany(mappedBy = "home")
private List<Person> people = new LinkedList<>();
public class HomeId implements Serializable {
private String address;
private String bed;
I'm trying to store a home and then a person with the home:
Home home = new Home();
home.setAddress("address");
home.setBed("bed");
entityManager.persist(home);
Person person = new Person();
person.setName("name");
person.setHome(home);
entityManager.persist(person);
The home get's saved correctly but when it comes to a person I get the following exception:
org.springframework.orm.jpa.JpaSystemException: No part of a composite identifier may be null; nested exception is org.hibernate.HibernateException: No part of a composite identifier may be null
How can I make it work? Please, add any ideas, any are appreciated!