say have @mappedsuperclass
this:
@mappedsuperclass public abstract class rating { @id private long id; @column(name="user_id") private long userid; private int rating; ...
with concrete child entity this
@entity @table(name="activity_rating") public class activityrating extends rating { private long activityspecificdata; ...
then there spring data jpa repository this:
@norepositorybean public interface ratingrepository<r extends rating> extends jparepository<r, id> { public list<r> findbyuserid(long userid); ...
and this:
public interface activityratingrepository extends ratingrepository<activityrating> { }
this works great , can call findbyuserid()
on of specific rating repositories extend ratingrepository
. wanting write jpql in ratingrepository
child interfaces can inherit. don't know (or if it's possible) put after from
in query. example:
@query("select new com.foo.ratingcountvo(e.rating, count(e.rating)) ??????? e group e.rating") public list<ratingcountvo> getratingcounts();
i can add method each of individual repositories extend ratingrepository
same except specific entity name. if want change query, i'd have go child repositories , update them individually. want query live in parent class , not duplicated. there way accomplish this?
i'm using spring-data-jpa 1.7.2 , eclipselink 2.5.2. i'm not opposed switching newer versions if necessary.
will work if split query 3 parts: start, entity , end of query? than, if it'll work, in each interface define constant
string entity = "activityrating";
and can use like
@query(ratingrepository.query_start + entity + ratingrepository.query_end) list<ratingcountvo> getratingcounts();
btw, there no need define public modifier in interface.
update: here described way:
@query("select new com.foo.ratingcountvo(e.rating, count(e.rating)) #{#entityname} e group e.rating
Comments
Post a Comment