2016-04-03 15 views
0

enter image description hereは、私は<strong>は3つのテーブル</strong>に参加することはできません

3つのテーブル(Hibernateの注釈例外、OneToMany、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; 

    ... 
} 

Hibernateの注釈例外:

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; 

変更エンティティRestaurantTable〜

@OneToMany(mappedBy = "restaurantTable") 
関連する問題