java - JPA/ Hibernate query child property -


i use single table strategy (with discriminator) use inheritance

uml schema => http://yuml.me/67acf6a6

i fetch orders of customer associations related (cars, books , tvs). know how achieve without breaking model classes.

@entity @table(name = "customers") public class customer{   private date birthdate;   private string name;    @onetomany(fetch = fetchtype.lazy, mappedby = "customer", cascade = cascadetype.all, orphanremoval = true)   @orderby("order")   private list<? extends order> orders; }  @entity @table(name = "orders") @inheritance(strategy = inheritancetype.single_table) @discriminatorcolumn(name = "type", discriminatortype = discriminatortype.string) public abstract class order{      @manytoone(fetch = fetchtype.lazy, optional = false)     @notnull     @joincolumn(name = "customerid")     private customer customer; }   @entity @discriminatorvalue("book") public class bookorder extends order {    @onetomany(fetch = fetchtype.lazy, cascade = cascadetype.all, orphanremoval = true)   @joincolumn(name="book_id")   private set<book> books; }  @entity @discriminatorvalue("car") public class carorder extends order {    @onetomany(fetch = fetchtype.lazy, cascade = cascadetype.all, orphanremoval = true)   @joincolumn(name="car_id")   private set<car> cars; }  @entity @discriminatorvalue("tv") public class tvorder extends order {   @onetomany(fetch = fetchtype.lazy, cascade = cascadetype.all, orphanremoval = true)   @joincolumn(name="tv_id")   private set<tv> tvs;  } 

if i'm doing in hql

select cutomer customer customer inner join fetch customer.orders order left join fetch order.cars left join fetch order.books left join fetch order.tvs 

i'm getting error

org.hibernate.queryexception: not resolve property: cars,  

it makes sense in abstract class order field doesnt exist.

do know how can achieve ? recommendation of hibernate in case ?

my goal simple simple query , fetch everything.

if following query

select c customer c join fetch c.orders 

then retrieve customers types of orders (cars | books | tvs). orders polymorphic, if instanceof each customer.orders element can determine type of order element is.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -