I have a set of composite keys, that later became a part of a Foreign key in other entity, and resulted in becoming part of the Primary key of such entity. So I ended having the following Embeddable objects.
Code:
@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;
....
}
So I have to different embeddable objects, one for the PK of an entity called Product, and the other for an entity called Application.
The problems comes when hibernate scanned my Application entity (see snippet below)
Code:
@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 complains with the following error
Code:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: ProductId in Application