Hibernate annotations do not work for getters, but work for attributes

I ran into a problem with sleep mode annotations. For the code shown below, I have a hotel class, a customer class, and I use customerhotelbooking to keep track of which customer booked that hotel and vice versa. but when I put annotations on the hotel and client getters, it gives an exception, and surprisingly it works when I put it in attributes. can anyone say why this is so?

`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)`

I have a bean hotel as shown `

@Id
 @GeneratedValue
 private int id;

 private String description;

 private String city;

 private String name;

 private String rating ;

 private int isBooked; 
 `

Cusomer bean like `

        @Id
 @GeneratedValue
 private int id;

 private String userName;

 private String password;

`

and CustomerHotelBooking class as

       @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;
 }
+5
source share
1 answer

The docs say:

2.2.2.2. Type of access

@Id @EmbeddedId. , . , , /. .

, - - .

( , , , @Access, - . )

+6

All Articles