【发布时间】:2011-07-20 02:10:33
【问题描述】:
我正在尝试执行 JPA/Hibernate 映射来映射两个表,但出现此错误。任何帮助将不胜感激!
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;}
}
出现此错误
线程“主”org.hibernate.MappingException 中的异常:不能 确定类型:bb.entities.Restaurants,在表:MENUS,对于 列:[org.hibernate.mapping.Column(restaurant)] 在 org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306) 在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290) 在 org.hibernate.mapping.Property.isValid(Property.java:217) 在 org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464) 在 org.hibernate.mapping.RootClass.validate(RootClass.java:235) 在 org.hibernate.cfg.Configuration.validate(Configuration.java:1362) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865) 在 bb.TestMain.setUp(TestMain.java:26) 在 bb.TestMain.main(TestMain.java:59)
谢谢。
【问题讨论】:
标签: jpa hibernate-mapping