当前位置: 首页 > 知识库问答 >
问题:

无法在JPA Springboot中找到具有逻辑名称的列[重复]

段坚
2023-03-14

有两个表。酒店内的地址。我已经提到了OneTo很多关系。但是编译器抛出错误。

创建名为entityManagerFactory的bean时出错,该bean在类路径资源[org/springFramework/boot/autoconfiure/orm/jpa/HibernateJpaConfiguration.class]中定义:调用init方法失败;嵌套异常org.hibernate.MappingException:无法在org.hibernate.mapping.Table(地址)及其相关的超级表和辅助表中找到逻辑名称为addressId的列

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;

住址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;
}

我尝试了一些变量名的更改,也仔细检查了我是否遗漏了什么。但是看起来我遵循了与其他Stack Overflow问题中提到的相同的方式。我错过了什么吗?

共有1个答案

宗烨赫
2023-03-14

referencedColumnName应指的是@列名称,而不是java属性名称
referencedColumnName值从addressId更改为address\u id

 @JoinColumn(name = "hotel_address", referencedColumnName = "address_id")
        private Address hotelAddress;
 类似资料: