I have the following entities with single table inheritance strategy.
@Entity
@Inheritance
@DiscriminatorColumn(name="type")
public abstract class Vehicle extends com.avaje.ebean.Model {
@Id
public Long id;
public String name;
public String description;
}
@Entity
@DiscriminatorValue("b")
public class Bus extends Vehicle {
public String field1;
}
@Entity
@DiscriminatorValue("c")
public class Car extends Vehicle {
public String field2;
}
I have a table in my UI that should show rows with columns of Vehicle's fields. I want to put an advanced search that user can filter Vehicles list by their types.
My question is how can I create a query to filter list by Vehicle's type. Something like this:
List<Vehicle> list = com.avaje.ebean.Ebean.find(Vehicle.class)
.where().eq("type", "c").findList();
If I insert a field with below definition that have been discussed here, I would get an error with message "Error injecting constructor, java.lang.IllegalStateException: Property theType not found in [id, name, description] for type class models.Vehicle"
@Column(name = "type", insertable = false, updatable = false)
public String theType;
If I set it to @Transient, I could not use it in queries.