I'm having a serious issue with JPA's implementation of OneToMany relationships and I'm looking for a reasonable workaround. The issue is that JPA appears to get confused reading it's @OneToMany annotation and returns:
"Flea.dog" declares a column that is not compatible with the expected type "blob".
Flea.dog is a numeric field. The issue appears to be a known bug: https://issues.apache.org/jira/browse/OPENJPA-1481
The issue is created as follows: I have two entities Dog and Flea, A Dog has many fleas represented by a dog_id in the Flea table. These entities are mapped to tables with different names Dog is mapped to Madra, Flea is mapped to feithidi.
The tables are as follows:
CREATE TABLE madra (dogid BIGINT, name varchar(255), PRIMARY KEY (dogid));
CREATE TABLE feithidi (fleaid BIGINT, dogid BIGINT, PRIMARY KEY (fleaid));
I'm using H2 for the example, though I've had the same issue on Oracle.
The entities are as follows:
@Entity(name="feithidi")
Flea{
@Id
long fleaid;
@ManyToOne
@JoinColumn(name="dogid", insertable=false, updatable=false, nullable=true)
private Dog dog;
}
and
@Entity(name="madra")
Dog{
@Id
long dogid;
String name;
@OneToMany(mappedBy="dog")
private Set<Flea> fleas;
}
The full exception I am returned is:
( org.apache.openjpa.persistence.ArgumentException: "Flea.dog" declares a column that is not compatible with the expected type "blob".
If anyone has a work around or can see an obvious error on my part I'd be grateful for some feedback.
Got the same error message because I had forgot to put the Dog-entity in the persistence.xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With