1

我有两个实体的以下复合键

@Embeddable
public class ProductId implements Serializable {
    @Column(name = "Id", columnDefinition = "bigint identity(1,1)")
    private Long id;

    @Column(name = "ProductTypeName")
    private String name;
....
}

@Embeddable
public class ApplicationId implements Serializable{
    @Column(name = "Id", columnDefinition = "bigint identity(1,1)",
            nullable = false, insertable = false, updatable = false)
    private Long id;
    @Embedded
    @AttributeOverride(name="id",
                       column=@Column(name="ProductId",
                                  columnDefinition = "bigint identity(1,1)",
                                  nullable = false, insertable = false,
                                  updatable = false))
    private ProductId productId;
....
}

我有两个不同的实体,都有上面定义的复合键。我的问题是嵌套复合键,我试图让它工作,但是当休眠扫描具有 ApplicationId 可嵌入对象作为其 PK 的实体时它失败了(这是给出问题的映射)

@Entity(name = "Application")
@Table(name = "Application")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Application {

    @EmbeddedId
    private ApplicationId applicationPk;

    @MapsId("productId")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumns({@JoinColumn(name = "ProductId", referencedColumnName = "Id",
                           nullable = false, insertable = true,
                           updatable = true),
                  @JoinColumn(name = "ProductTypeName",
                           referencedColumnName = "ProductTypeName",
                           nullable = false, insertable = true,
                           updatable = true)})
    @ForeignKey(name = "FK_Application_Product")
    private Product product;
....}

Hibernate 抱怨以下错误Caused by: org.hibernate.MappingException: Unable to find column with logical name: ProductId in Application

4

0 回答 0