嵌套复合键

时间:2012-08-29 19:20:24

标签: hibernate jpa composite-key

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

@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;
....
}

我有两个不同的实体都带有上面定义的复合键。我的问题是嵌套复合键,我试图将其用于工作但是当hibernate扫描具有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

0 个答案:

没有答案