You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Joakim Olsson <ar...@lingonpaj.com> on 2009/02/23 23:27:15 UTC
"No field named"-problem when using subclass field in where-clause
Hi all,
I have a problem when trying to find objects of a base-class by using a
field from one of the subclasses in the where-clause.
The error I get is a 'No field named "xxx" in class "yyy"'. Hibernate
resolves this kind of query but OpenJPA obviously does not.
Example:
Base-class:
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@DiscriminatorColumn(name = "type", discriminatorType =
DiscriminatorType.STRING)
public class Consumer extends AbstractBaseEntity {
@Id
private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}
Subclass 1:
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("Person")
public class Person extends Consumer {
private String firstName;
private String lastName;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Subclass 2:
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("Organisation")
public class Organisation extends Consumer {
private String legalName;
public String getLegalName() {
return this.legalName;
}
public void setLegalName(String legalName) {
this.legalName = legalName;
}
}
Query:
Select c From Consumer c Where c.firstName = ?1
Is there a way to make OpenJPA understand my query?
Regards,
Joakim