2 つのエンティティに対して次の複合キーがあります。
@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;
....
}
上記で定義された複合キーを持つ 2 つの異なるエンティティがあります。私の問題は、複合キーをネストすることです。これを機能させようとしていますが、ApplicationId 埋め込み可能オブジェクトを PK として持つエンティティを hibernate スキャンすると失敗します (問題を引き起こしているもののマッピングは次のとおりです)。
@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