java - JPA/Hibernate how to get N items of each category -
java - JPA/Hibernate how to get N items of each category -
let's assume have next auto entity in database: id, name, model.
i want retrieve n cars of each model. brevity sake, if have next models: bmw, porche, volkswagen, want 2 bmw, 2 porche, , 2 volkswagen.
is achievable through either single hql or sql query ?
the best i've achieved far using 3 separate queries each model.
not directly, no.
even plain sql have utilize union accomplish , not supported in hql.
what create view (for union) , map auto entity.
http://timezra.blogspot.de/2009/05/mapping-hibernate-entities-to-views.html
java mysql sql hibernate hql
Comments
Post a Comment