我有一个非常简单的问题。我不知道是我没有理解什么,还是我不知道该怎么做。我很长一段时间想知道hibernate spring中如何一对一。我可以从两个方向到达桌子。假设我有 Hotel 和 hotelDetails 表。正在为我创建一个密钥,以便我可以从酒店访问 hotelRating,但我不能走其他路。有时这对我很重要。我将使用示例代码。public class Hotel {    private Long id;    private String name;    private String currency;    private String image;    private HotelRating hotelRating;    @Id    @Column(name = "id")    @GeneratedValue(strategy = GenerationType.AUTO)    public Long getId() {        return id;    }    public void setId(Long id) {        this.id = id;    }.    .    @OneToOne(cascade = CascadeType.ALL)    @JoinColumn(name = "hotel_rating_id", referencedColumnName = "id")    public HotelRating getHotelRating() {        return hotelRating;    }    public void setHotelRating(HotelRating hotelRating) {        this.hotelRating = hotelRating;    }酒店评级表。问题是,当我试图让 getter 和 setter 做酒店时。我得到:org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]中定义的名为“entityManagerFactory”的bean时出错:调用init方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] 无法构建 Hibernate SessionFactory;嵌套异常是 org.hibernate.MappingException:无法确定类型:com.flightradar.flightradar.model.hotel.Hotel,表:hotel_ rating,列:[org.hibernate.mapping.Column(hotel)]@Entity@Table(name = "hotel_rating")public class HotelRating {    private long id;    private Integer votesNumber;    @Min(1)    @Max(5)    private Double average;    @OneToOne(mappedBy = "hotel_rating")    Hotel hotel;    @Id    @Column(name = "id")    @GeneratedValue(strategy = GenerationType.AUTO)    public long getId() {        return id;    }    public void setId(long id) {        this.id = id;    }所以,大家帮助我了解从 HotelRating Table 到达 Hotel table 的最简单的可能性。例如,我有 HotelRating 列表,我必须从 Hotel 表中获取每个 hotelRanking 对象。
                    
                    
                1 回答
 
                    
                    
                            弑天下
                            
                                
                            
                        
                        
                                                
                    TA贡献1818条经验 获得超8个赞
类中的“mappedBy”值HotelRating必须提供
拥有关系的字段。
在您的示例中,该值为“hotel_ rating”
@OneToOne(mappedBy = "hotel_rating") Hotel hotel;
但课堂上没有这个字段Hotel。相应的字段可能是“hotelRating”。
添加回答
举报
0/150
	提交
		取消
	