Hibernate Error: Could not resolve attribute ‘orderingRoom’ of ‘BookingOrder’ (Spring Data JPA, Table-Per-Class Inheritance)

Context:

I’m working on a Spring Data JPA application with table-per-class inheritance. I’m encountering an error when trying to write a JPQL query to retrieve booking orders for a specific room and filter them based on their status.

Code Snippets:

Order.java (Super Class):
Java
package com.TravelConcierge.Hotel.Entity.order;

import com.TravelConcierge.Hotel.Enomiration.OrderStatus;
import com.TravelConcierge.Hotel.Entity.Room;
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;

@Data
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "orders")
public abstract class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private Long id;

    @Column(nullable = false)
    private String orderNumber;

    @Column(nullable = false)
    private LocalDateTime createdAt;

    @ManyToOne(fetch = FetchType.EAGER)  // This might need adjustment
    @JoinColumn(name = "room_id")
    private Room orderinghoom;  // Typo: should be orderingRoom

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private OrderStatus status;

    @Column(nullable = false)
    private String confirmationCode;
}

Use code with caution.
content_copy
BookingOrder.java (Sub Class):
Java
package com.TravelConcierge.Hotel.Entity.order;

import com.TravelConcierge.Hotel.Entity.Room;
import jakarta.persistence.*;
import lombok.*;
import java.time.LocalDate;

@EqualsAndHashCode(callSuper = true)
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class BookingOrder extends Order {

    @Column(nullable = false)
    private LocalDate checkInDate;

    @Column(nullable = false)
    private LocalDate checkOutDate;

    @OneToOne
    @JoinColumn(name="resarvedroom_id")  // Typo: should be reservedRoomId
    private Room room;
}

Use code with caution.
content_copy
BookingRepository.java:
Java
package com.TravelConcierge.Hotel.Repository;

import com.TravelConcierge.Hotel.Entity.order.BookingOrder;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BookingRepository extends JpaRepository<BookingOrder,Long> {

    @Query("SELECT c FROM BookingOrder c " +
     "WHERE c.orderingRoom.id IN (SELECT r.id FROM Room r WHERE r.id = :roomId) " +             
     "AND (c.status = 'ON-WAY' OR c.status = 'SETTED')")
    List<BookingOrder> findByRoomIdAndStatus(@Param("roomId") Long roomId);
}

Use code with caution.
content_copy
Error Message:

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.TravelConcierge.Hotel.Repository.BookingRepository.findByOrderinghoomIdAndStatus(java.util.List);

Caused by: org.hibernate.query.sqm.UnknownPathException: Could not resolve attribute ‘orderingRoom’ of ‘com.TravelConcierge.Hotel.Entity.order.BookingOrder’
Question:

I’ve fixed some typos in the code (orderinghoom to orderingRoom, resarvedroom_id to reservedRoomId), but I’m still getting the error. Why can’t Hibernate resolve the orderingRoom attribute in the JPQL query? How can I fix this error to retrieve booking orders for a specific room and filter them by status?

Additional Information:

I’m using Spring Data JPA with table-per-class inheritance.
The Order class is annotated with @Entity.
The @ManyToOne annotation is used on the orderingRoom field in the Order class (might need adjustment based on inheritance strategy).
Desired Outcome:

I want to be able to use the findByRoomIdAndStatus method in my repository to retrieve booking orders for a specific room and filter them based

New contributor

Desta Equar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật