我有一个像这样的本地SQL查询
@Query(value = "select b.bookingID,b.rentDate,b.returnDate,b.custNICNumber,b.bookingStatus,rd.lossDamage,rd.driverNICNumber,rd.vehicleRegID " +
"from booking b,bookingdetails rd where (b.bookingID=rd.bookingID) and b.bookingStatus='Rejected' && rd.vehicleRegID=?", nativeQuery = true)
Booking getReturn(String vehicleRegID);
当我运行我的程序时,我得到一个错误信息。
could not execute query; SQL nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
但在正常的SQL中(不用Hibernate),我的查询工作正常。
Booking Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Booking {
@Id
private String bookingID;
private Date rentDate;
private Date returnDate;
private String bookingStatus; //For Admin Approvel
private String rentStatus;
@ManyToOne
@JoinColumn(name = "custNICNumber", referencedColumnName = "custNICNumber")
private Customer custNICNumber;
@OneToMany(mappedBy = "bookingID")
private List<BookingDetails> bookingDetails = new ArrayList<>();
BookignDetails Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class BookingDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int bookingDetailsID;
private double lossDamage;
private String lossDamageImage;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "bookingID", referencedColumnName = "bookingID")
private Booking bookingID;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "vehicleRegID", referencedColumnName = "vehicleRegID")
private Vehicle vehicleRegID;
@ManyToOne
@JoinColumn(name = "driverNICNumber", referencedColumnName = "driverNICNumber",nullable = true)
private Drivers driverNICNumber;