我的项目正在使用JPA2 / hibernate将属性映射到它们各自的表。据我了解,我必须将属性mappedby
放在所有者表中,并将JoinColumn
放在子表中(许多方面)。我收到了如下所示的错误:
由以下原因引起:org.hibernate.AnnotationException:mappedBy引用了 目标实体属性未知: ninja.familyhomestay.domain.HouseImage.homestay_info在 ninja.familyhomestay.domain.HomestayInfo.houseImages
这是我的HomestayInfo类:
@Entity
@Table(name = "homestay_info")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "homestay_info")
data class HomestayInfo(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
var id: Long? = null,
...
@OneToMany(mappedBy = "homestay_info", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
var houseImages: MutableSet<HouseImage> = HashSet(),
...
)
和我的houseImage类:
@Entity
@Table(name = "house_image")
@Document(indexName = "house_image")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
class HouseImage(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
var id: Long? = null,
...
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "homestay_info_id")
var homestayInfo: HomestayInfo? = null
) : Serializable
有什么想法吗?我还使用Liquid在db中创建表。
答案 0 :(得分:1)
在您的HomestayInfo
类中,当提及@OneToMany
关系时,您将mappedBy
属性的值提到为homestay_info
,而在HouseImage
类中则没有名为homestay_info
的字段。
您应该具有与namedBy中提到的字段名称相同的属性,并且该属性应在另一个类中指定双边关系。
在以下语句中将 homestayInfo 重命名为 homestay_Info :
var homestayInfo: HomestayInfo? = null
或
将mappedBy
字段中的值重命名为 homestayInfo