I get this failure by mapping a OneToOne-Relationship:
Code:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: myEntities.Product$ProductID, got class myEntities.Item$ItemID
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
The ProductID of table Product is a composite key which has the SAME Columns than the composite key ItemID in table Item:
Code:
public class Product implements Serializable {
public static class ProductID implements Serializable
{
@Column(name = "ID_A", nullable = false, columnDefinition = "integer")
private Integer idA;
@Column(name = "ID_B", nullable = false, columnDefinition = "integer")
private Integer idB;
}
@EmbeddedId
private ProductID productID = new DocumentID();
getter/setter
@OneToOne(fetch = FetchType.EAGER, optional = true)
@JoinColumns({
@JoinColumn(name="ID_A", referencedColumnName="ID_A", nullable = false, insertable = false, updatable = false),
@JoinColumn(name="ID_B", referencedColumnName="ID_B", nullable = false, insertable = false, updatable = false) })
private Item item;
//getter/setter
}
Code:
public class Item implements Serializable {
public static class ItemID implements Serializable
{
@Column(name = "ID_A", nullable = false, columnDefinition = "integer")
private Integer idA;
@Column(name = "ID_B", nullable = false, columnDefinition = "integer")
private Integer idB;
}
@EmbeddedId
private ItemID itemID = new ItemID();
getter/setter
@OneToOne(fetch = FetchType.EAGER, optional = true, mappedBy="item")
private Product product;
//getter/setter
}
This HQL works and returns the item-instance of a product:
Code:
select a.item from Product a
This HQL does not work and returns the exception:
Code:
select a from Product a
Code:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: myEntities.Product$ProductID, got class myEntities.Item$ItemID
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
Instead of JoinColumn, I have tried it with PrimaryKeyJoinColumns (the same exception occurs):
Code:
@OneToOne(fetch = FetchType.EAGER, optional = true)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="ID_A", referencedColumnName="ID_A"),
@PrimaryKeyJoinColumn(name="ID_B", referencedColumnName="ID_B", nullable = false, insertable = false, updatable = false) })
private Item item;
(Another point is, when I annotate the @OneToOne above the getter instead above the field, then Hibernate totally ignores my OneToOne-Mapping and recognices the Item-Instance (or Product-Instance) as a column instead of a relationship, hence it produces false sql-selects)
What is wrong with my mapping?