1

There are two tables. Address inside Hotel. I have already mentioned OneToMany relation. But compiler throwing error.

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to find column with logical name: addressId in org.hibernate.mapping.Table(address) and its related supertables and secondary tables

Hotel.java

@AllArgsConstructor
@Data
@Entity
@Table(name = "hotels")
@NoArgsConstructor
public class HotelEntity {

    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "hote_id")
    private String hotelId;
    @Column(name = "hotel_name")
    private String hotelName;
    @Column(name = "build_date")
    private Date buildDate;
    @Column(name = "guest_type") @Enumerated(EnumType.STRING)
    private GuestType guestType;
    @Column(name = "room")
    @OneToMany(targetEntity = RoomEntity.class,cascade = CascadeType.ALL)
    @JoinColumn(name = "hotel_room", referencedColumnName = "roomId")
    private List<Room> room;
    @OneToOne(targetEntity = AddressEntity.class,cascade = CascadeType.ALL)
    @JoinColumn(name = "hotel_address", referencedColumnName = "addressId")
    private Address hotelAddress;

Address.java

@Entity
@Table(name = "ADDRESS")
@Getter
@Setter
@ToString
@RequiredArgsConstructor
public class AddressEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "address_id")
    private String addressId;
    @Column(name = "street_name")
    private String streetName;
    @Column(name = "city")
    private String city;
    @Column(name = "zip_code")
    private String zipCode;
    @Column(name = "country")
    private String country;
}

I tried some changing in variable name also double checked if I am missing something. but looks I have followed same way as mentioned in other Stack Overflow questions. Am I missing something?

4
  • Somebody closed this question and marked it as duplicate with wrong reference. This question is totally different from that one. Please accept the answer below if it solved your problem to help the others who may stumble on the same issue Commented May 23, 2022 at 19:14
  • How do i make it solve? Commented May 24, 2022 at 6:58
  • @ChetanAhirrao The way it was closed by only "Community" means the OP accepted a duplicate suggested by a close flag. In other words, the OP thinks (or thought) it answers the question. Commented May 24, 2022 at 10:45
  • Oh. Thanks for the clarification. Just thought that it would misguide someone in the future Commented May 24, 2022 at 11:56

1 Answer 1

1

referencedColumnName shall refer to the @Column name and not java attribute name
Change referencedColumnName value from addressId to address_id

 @JoinColumn(name = "hotel_address", referencedColumnName = "address_id")
        private Address hotelAddress;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.