我面臨着hibernate註釋的問題。對於下面顯示的代碼,我有一個酒店類,客戶類,我使用customerhotelbooking來跟蹤哪個客戶預訂了哪家酒店和副店-versa。 但是,當我把註釋放在酒店和客戶的getter上時,它會給出一個異常,並且當我將它放在屬性上時它會有效。 有人可以告訴爲什麼這樣嗎?Hibernate註解不適用於getters,但適用於屬性
`Caused by: org.hibernate.MappingException: Could not determine type for: com.xebia.hotelBooking.domain.Customer, at table: CustomerHotelBooking, for columns: [org.hibernate.mapping.Column(customer)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:290)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:274)
at org.hibernate.mapping.Property.isValid(Property.java:217)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464)
at org.hibernate.mapping.RootClass.validate(RootClass.java:236)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1193)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1378)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
at org.jboss.seam.Component.callCreateMethod(Component.java:2172)
at org.jboss.seam.Component.newInstance(Component.java:2132)`
我有酒店豆如`
@Id
@GeneratedValue
private int id;
private String description;
private String city;
private String name;
private String rating ;
private int isBooked;
`
Cusomer bean作爲`
@Id
@GeneratedValue
private int id;
private String userName;
private String password;
`
和CustomerHotelBooking類作爲
@Id
@GeneratedValue
private int id;
private Hotel hotel;
private Customer customer;
@ManyToOne
@Cascade(value = { CascadeType.ALL })
public Customer getCustomer() {
return customer;
}
/**
* @param customer the customer to set
*/
public void setCustomer(Customer customer) {
this.customer = customer;
}
/**
* @return the user
*/
/**
* @return the hotel
*/
@ManyToOne
@Cascade(value = { CascadeType.ALL })
public Hotel getHotel() {
return hotel;
}
/**
* @param hotel
* the hotel to set
*/
public void setHotel(Hotel hotel) {
this.hotel = hotel;
}
感謝Bozho ...得到了你的觀點:) – Mann 2010-11-17 08:56:50
不能將我的ID註釋移動到ID getter方法... – 2013-08-15 12:33:52