Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenJPA treats field with oneToMany Mapping as a Blob

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.

like image 691
Lindalinian Avatar asked Mar 29 '11 13:03

Lindalinian


1 Answers

Got the same error message because I had forgot to put the Dog-entity in the persistence.xml.

like image 139
annkatrin Avatar answered Oct 03 '22 05:10

annkatrin