0

I have queries joining multiple tables and, stored procedures which are being called by Named Native Queries in package-info.java. How do I map the data using SQLResultSetMapping? I get "Annotation type not applicable to this kind of declaration" error for @SQLResultSetMapping. This code was working fine in Java 6 but does not compile in Java 8.

@org.hibernate.annotations.NamedNativeQueries({

    @org.hibernate.annotations.NamedNativeQuery(name = "get_user",
        query = "select table1. id, display from table1 inner join table2 on table1.id = table2.id",
        resultSetMapping = "mapping"
    ),
 @org.hibernate.annotations.NamedNativeQuery(name = "get_id",
        query = "call PKG.test(?,:x,:y)",
        callable = true,
        readOnly = false,
        resultSetMapping = "output_info"
    ),

})

@SqlResultSetMappings({   
    @SqlResultSetMapping(name = "mapping",
    columns = {
        @ColumnResult(name = "id"),
        @ColumnResult(name = "display")
    }),
    @SqlResultSetMapping(name = "output_info",
    columns = {
        @ColumnResult(name = "count")
    })
})

package abc.domain;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMap

This is my dao.java:

public List<Object[]> getUser(long sessionId) {
    String[] params = new String[]{"x"};
    Object[] values = new Object[]{x};
    List result = getHibernateTemplate().findByNamedQueryAndNamedParam("get_user", params, values);
    return result;
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
redds1
  • 5
  • 4

1 Answers1

0

As mentioned by Mark Rotteveel, they need to be declared in the Entity class.

redds1
  • 5
  • 4