我正在尝试执行映射两个表的JPA/Hibernate映射,但遇到此错误。任何帮助将不胜感激!!JPA @OneToMany映射问题
Restaurants.java
@Entity
@Table(name="RESTAURANTS")
public class Restaurants{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@OneToMany(mappedBy="restaurant")
private LinkedList<Menus> menus = new LinkedList<Menus>();
/* constructors **/
public Restaurants(){
this.dateJoined = new Date();
};
/* getters and setters **/
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
public LinkedList<Menus> getMenus() {return menus;}
public void setMenus(LinkedList<Menus> menus) {this.menus = menus;}
}
Menus.java
@Entity
@Table(name = "MENUS")
public class Menus {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private Long restaurantID;
@OneToMany
@JoinColumn(name="restaurant")
private Restaurants restaurant;
/* constructors */
public Menus(){}
/* getters and setters */
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
@Column(nullable = false)
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
public Long getRestaurantID() {return restaurantID;}
public void setRestaurantID(Long restaurantID) {this.restaurantID = restaurantID;}
public void setRestaurant(Restaurants restaurant) {this.restaurant = restaurant;}
public Restaurants getRestaurant() {return restaurant;}
}
有了这个错误
线程“main”中的异常org.hibernate.MappingException:不能 确定类型为:bb.entities.Restaurants,在表中:MENUS, 列:[org.hibernate.mapping.Column(restaurant)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)处 org.hibernate.mapping.Property.isValid org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290)(Property.java :217)at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464) at org.hibernate.mapping.RootClass.validate(RootClass.java:235)at org.hibernate.cfg.Configuration.validate (Configuration.java:1362)at org.hibernate.cfg.Configuration.bui ldSessionFactory(Configuration.java:1865) 在bb.TestMain.setUp(TestMain.java:26)在 bb.TestMain.main(TestMain.java:59)
感谢。