java - JPA Data Repositories with SqlResultSetMapping and native queries -


i stuck following situation:

my entities related each other, in such way not use jpql. forced use native sql. want map these results valueobject. clear, don't want list of object array (list<object[]>). have 6 entities need columns. can give me example on how implement such mapping native query?

tutorial went through.

my code:

@sqlresultsetmapping(     name = "findalldatamapping",     classes = @constructorresult(             targetclass = myvo.class,             columns = {                     @columnresult(name = "userfirstname"),                     @columnresult(name = "userlastname"),                     @columnresult(name = "id"),                     @columnresult(name = "packagename")             }     ) )  @namednativequery(name = "findalldatamapping",     query = "select " +             "    u.first_name userfirstname, " +             "    u.last_name userlastname, " +             "    i.id id, " +             "    s.title packagename, " +             "from " +             "    invoice " +             "join user u on i.user_id=u.id " +             "left join subscription_package s on i.subscription_package_id=s.id " +             "where  u.param1=:param1 , i.param2=:param2" + )  public class myvo {     private string userfirstname;     private string userlastname;     private long id;     private string packagename;      public myvo (string userfname, string userlname,             long id, string packagename) {         this.userfirstname = userfname;         this.userlastname = userlname;         this.id = id;         this.packagename = packagename;     }      // getters & setters } 

in jpa-repository module:

public interface myrepository extends jparepository<myentity, long> {     list<myvo> findallofmyvo(@param("param1") string param1, @param("param2") string param2); } 

the point don't know put these annotations can use kind of mapping. in native query can't use new rs.rado.leo.mypackage.myvo(...). got following error:

caused by:

org.springframework.data.mapping.propertyreferenceexception: no property findallofmyvo found type myentity! 

i suppose question clear. if not, let me know can edit question.

thanks in advance!

you need mark query query :) , need use myvo instead of myentity, because entity have resulsts mapped to

@repository public interface myrepository extends jparepository<myvo, long> {      @query(nativequery = true)     list<myvo> findallofmyvo(@param("param1") string param1, @param("param2") string param2); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -