Home > Back-end >  Hibernate for composite primary key query error
Hibernate for composite primary key query error

Time:10-08

Error: Unable to locate the Attribute with the the given name [rombokid. Room_id] on this ManagedType [Hibernate. Domain. Rom_bok]


This is a primary key class:
Package Hibernate. Domain;
Import the Java. IO. Serializable.

Public class Rom_bok_id implements Serializable {
Private Long room_id;
Private Long booking_id;

Public void setroom_id (Long room_id) {
Enclosing room_id=room_id;
}

Public Long getroom_id () {
Return this. Room_id;
}

Public void setbooking_id (Long booking_id) {
Enclosing booking_id=booking_id;
}

Public Long getbooking_id () {
Return this. Booking_id;
}


@ Override
Public int hashCode () {

Final int prime=31;
Int result=1;
Result=prime * result + ((room_id==null)? Zero: room_id hashCode ());
Result=prime * result + ((booking_id==null)? Zero: booking_id hashCode ());
return result;


}

@ Override
Public Boolean equals (Object obj) {
If (this==obj)
return true;
If (obj==null)
return false;
If (getClass ()!=obj. GetClass ())
return false;
Rom_bok_id other=(Rom_bok_id obj);
If (room_id==null) {
If (other room_id!=null)
return false;
} else if (! Room_id. Equals (other. Room_id))
return false;
If (booking_id==null) {
If (other booking_id!=null)
return false;
} else if (! Booking_id. Equals (other. Booking_id))
return false;
return true;
}


}

This is mapping class
Package Hibernate. Domain;

Public class Rom_bok {
Private Booking Booking;
Private Room Room;
Private Boolean booked;
Private Rom_bok_id rombokid;
Public Rom_bok_id getrombokid () {
Return rombokid;
}
Public void setrombokid (Rom_bok_id rombokid) {
Enclosing rombokid=rombokid;
}
Public Booking getbooking () {
Return this. The booking;
}


Public void setbooking (Booking Booking) {
This. Booking=booking;
}

Public void setroom Room (Room) {
This. Room=room;
}
Public Room getroom () {
Return this. The room;

}
Public void setbooked (Boolean booked) {
This. Booked=booked;
}
Public Boolean getbooked () {
Return this. Booked;
}


}


The mapping file is as follows:

<? The XML version="1.0" encoding="utf-8"?>
"Http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" & gt;


















Query methods below


Public void findCustomerByRoomId (Long room_id) {
The Session Session.=HotelCmiHibernateSessionFactory getSession ();
The Transaction Transaction=session. BeginTransaction ();
//(1) the direct use of Hibernate CRUD functionality
CriteriaBuilder builder=session. GetCriteriaBuilder ();
CriteriaQueryRootCriteria. Select (root. Get (" rombokid "));
Criteria. The where (builder. Equal (root) get (" rombokid. Room_id "), room_id));
QueryRom_bok m=query uniqueResult ();
Rom_bok_id rbi=m.g etrombokid ();

System. The out. Println (rbi) getbooking_id ());
Transaction.com MIT ();
session.close();


}


  • Related