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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mr.Shah
  • 61
  • 7
  • 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 – Chetan Ahirrao May 23 '22 at 19:14
  • How do i make it solve? – Mr.Shah May 24 '22 at 06: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. – Mark Rotteveel May 24 '22 at 10:45
  • Oh. Thanks for the clarification. Just thought that it would misguide someone in the future – Chetan Ahirrao May 24 '22 at 11:56

1 Answers1

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;
Chetan Ahirrao
  • 1,454
  • 11
  • 16