为什么我的嵌入式Id处于休眠状态无法正常工作?
2022-09-02 02:10:54
我在表中有一个复合主键,其中引用实体 HolidayPackage,在 HolidayPackageVariant 和 HolidayPackage 之间具有多对一关系。(IDHOLIDAYPACKAGE, IDHOLIDAYPACKAGEVARIANT)
HolidayPackageVariant
IDHOLIDAYPACKAGE
当我尝试在HolidayPackageVariant中执行复合PK映射时,我收到以下错误:
初始 SessionFactory creation failed.org.hibernate.annotations.common.AssertionFailure: 在继承状态层次结构中找不到声明类:org.wah.model.holidaypackageVariantPrimaryKey
有人可以告诉我我在这里做错了什么吗?
我的POJO看起来像这样:
假日包变量:
@Entity
@Table(name="HOLIDAYPACKAGEVARIANT")
public final class HolidayPackageVariant {
private HolidayPackageVariantPrimaryKey idCompound;
@EmbeddedId
public HolidayPackageVariantPrimaryKey getIdCompound() {
return idCompound;
}
// other code
}
假日包可变主密钥
@Embeddable
public final class HolidayPackageVariantPrimaryKey implements Serializable {
private Integer idHolidayPackageVariant;
private HolidayPackage holidayPackage;
public HolidayPackageVariantPrimaryKey(){}
public HolidayPackageVariantPrimaryKey(int id, HolidayPackage pkg){
setIdHolidayPackageVariant(id);
setHolidayPackage(pkg);
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "IDHOLIDAYPACKAGEVARIANT", nullable = false)
public Integer getIdHolidayPackageVariant() {
return idHolidayPackageVariant;
}
@Id
@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
@JoinColumn(name="IDHOLIDAYPACKAGE", nullable=false)
public HolidayPackage getHolidayPackage() {
return holidayPackage;
}
// equals and hashCode
}
假日包装
public final class HolidayPackage {
private Set<HolidayPackageVariant> holidayPackageVariants = new HashSet<HolidayPackageVariant>(0);
@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL}, mappedBy = "idCompound.holidayPackage")
public Set<HolidayPackageVariant> getHolidayPackageVariants() {
return holidayPackageVariants;
}
// other code
}