I am working with flight_management_system
where I have three entity UserEntity
, FlightEntity
and BookEntity
. UserEnity
is associated with BookEntity
and FlightEntity
is associated with BookEntity
. While i am trying to run my project I got error in eclipse ide.
Error
Caused by: org.hibernate.QueryException: could not resolve property: flightName of: com.flightbook.entity.FlightEntity
Here down is my code:
Entity
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String userName;
private String password;
@JsonBackReference("auth")
@ManyToOne(targetEntity = AuthGroupEntity.class)
@JoinColumn(name = "auth_id")
private AuthGroupEntity authGroupEntity;
@JsonManagedReference("booking")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userEntity")
private List<BookEntity> bookEntities;
}
public class FlightEntity {
@Id
private String flightId;
private String flightname;
private String from;
private String to;
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date scheduleDate;
@JsonManagedReference("flight")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "flightEntity")
private List<BookEntity> bookEntities;
}
public class BookEntity {
@Id
private String bookingId;
private String pasengerName;
private String status;
@JsonBackReference("flight")
@ManyToOne(targetEntity = FlightEntity.class)
@JoinColumn(name = "flight_id")
private FlightEntity flightEntity;
@JsonBackReference("booking")
@ManyToOne(targetEntity = UserEntity.class)
@JoinColumn(name = "user_id")
private UserEntity userEntity;
}
Model
public class BookingList {
private String bookingId;
private String pasengerName;
private String status;
private Date scheduleDate;
private String flightName;
public BookingList(String bookingId, String pasengerName, String status, Date scheduleDate, String flightName) {
this.bookingId = bookingId;
this.pasengerName = pasengerName;
this.status = status;
this.scheduleDate = scheduleDate;
this.flightName = flightName;
}
....
....
}
Repository
@Query("SELECT new com.flightbook.model.BookingList(b.bookingId, b.pasengerName, b.status, f.scheduleDate, f.flightName) FROM BookEntity b JOIN b.flightEntity f JOIN b.userEntity u WHERE u.id = ?1")
List<BookingList> getFlightBookingByUserId(Long user_id);
CodePudding user response:
Your property is flightname
not flightName
for FlightEntity