I am currently developing a java ee application but i am having problems with the JPA. I have two entities:
@Entitiy
public class Restaurant implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Desk> desks;
}
@Entitiy
public class Desk implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
@JoinColumn(name = "restaurant_id")
private Restaurant restaurant;
}
And i am storing the desks with the following code:
Desk desk = new Desk();
desk.setNumber(Integer.toString(x));
desk.setRestaurant(restaurant);
em.persist(desk);
But now the strange thing is that the list of desks in the entity restaurant is empty but the restaurant value in the entity desk is correct. The Database shema looks like that:
RESTAURANT (ID)
DESK (ID, RESTAURANT_ID)
RESTAURANT_DESK (RESTAURANT_ID, DESK_ID)
The table RESTAURANT_DESK is always empty. Why is this third table generated? And why is the list of desks in the entity restaurant empty?