I have a table with a composite key made up of a foreign key (bar_id) and a value (value). I'll call this table 'Foo'.
The foreign key (bar_id) serves as the @Id on its own entity, which I will call 'Bar'.
I have created an @Embeddable class (FooPk) to serve as the primary key for the Foo class. In that class is a variable of type Bar and another of type BigInteger. That would seemingly resolve to the bar_id and value that make up the composite key.
The problem is that the compiler is complaining about being unable to determine the type of the Bar variable in FooPk. The error reads:
Code:
org.hibernate.MappingException: Could not determine type for: com.jabekb.data.Bar, for columns: [org.hibernate.mapping.Column(bar)]
My current assumption is that this error stems from the fact that I'm asking Hibernate to walk Bar to determine how to get the identifier to pair with value for FooPk. Can this be done?
Here is the composite key class
Code:
@Embeddable
public class FooPk implements Serializable {
private static final long serialVersionUID = -1524952877179756052L;
private Bar bar;
private BigInteger value;
public FooPk(Bar bar, BigInteger value) {
this.bar = bar;
this.value = value;
}
public void setBar(Bar bar) {
this.bar = bar;
}
public Bar getBar() {
return bar;
}
public void setValue(BigInteger value) {
this.value = value;
}
public BigInteger getValue() {
return value;
}
@Override
public boolean equals(Object that) {
if(this == that) {
return true;
}
if(that == null) {
return false;
}
if(!(that instanceof FooPk)) {
return false;
}
FooPk thatFooPk = (FooPk) that;
if(bar.equals(thatFooPk.getBar()) && value.equals(thatFooPk.getValue())) {
return true;
}
return false;
}
@Override
public int hashCode() {
return (bar.hashCode() ^ value.hashCode());
}
}
Here is the important part of Foo.
Code:
@Entity
public class Foo{
@Id
private FooPk id;
private BigInteger value;
@ManyToOne
@JoinColumn(name="bar_id")
private Bar bar;
}
Here is the important part of Bar.
Code:
@Entity
public class Bar {
@Id
@Column(name="bar_id")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer barId;
}