2016-04-03 164 views
0

enter image description here加入三个表(休眠注释异常,一对多,的mappedBy)

我不能加入三个表。看到上面的图片。正如你所看到的,每个餐厅都可以有很多餐桌,每个餐桌都可以有很多预订。

餐厅实体:

@Entity 
@Table(name = "restaurant") 
public class Restaurant { 

    @Id 
    @Column(name = "id") 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 
    @Column(name = "name") 
    private String name; 
    @Column(name = "aadress") 
    private String aadress; 

    @OneToMany(mappedBy = "restaurant") 
    private List<RestaurantTable> restaurantTables; 
} 

RestaurantTable实体:

@Entity 
@Table(name = "restaurant_table") 
public class RestaurantTable { 

    @Id 
    @Column(name = "id") 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    @ManyToOne 
    @JoinColumn(name = "restaurant_id") 
    private Restaurant restaurant; 

    @Column(name = "number") 
    private int number; 
    @Column(name = "count") 
    private int count; 

    @OneToMany(mappedBy = "restaurant_table") 
    private List<Booking> bookings; 
} 

预定实体:

@Entity 
@Table(name = "booking") 
public class Booking { 

    @Id 
    @Column(name = "id") 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    @ManyToOne 
    @JoinColumn(name = "restaurant_table_id") 
    private RestaurantTable restaurantTable; 

    ... 
} 

休眠注释异常:

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: Booking.restaurant in RestaurantTable.bookings 

任何帮助表示赞赏!

回答

1

在RestaurantTable

@OneToMany(mappedBy = "restaurant_table") 
private List<Booking> bookings; 

你是指物业的预订#restaurant_table,但在预定实体类这个属性被命名为restaurantTable

@ManyToOne 
@JoinColumn(name = "restaurant_table_id") 
private RestaurantTable restaurantTable; 

变化实体餐厅表

@OneToMany(mappedBy = "restaurantTable")