jpa - Named Query to return a List<String> -
hello using dropwizard application.
the resource class
@path("/people") @produces(mediatype.application_json) public class peopleresource{ private persondao pdao; public peopleresource(persondao pdao) { this.pdao = pdao; } @get @timed @unitofwork public list<string> getallpeople() { return pdao.findall(); } }
the dao class
public class persondao extends abstractdao<person> { public persondao(sessionfactory factory) { super(factory); } public list<string> findall() { return list(namedquery("com.example.findall")); } public person create(person p) { return persist(p); }
the person class
@jsonignoreproperties(ignoreunknown = true) @entity @table(name = "person") @namedqueries({ @namedquery( name = "com.example.findall", query = "select distinct p.name person p" ) }) @jsonproperty string name;
but when try access resource fails saying in dao class method 'findall' should return list<person>
instead of list<string>
. missing? checked query teh database , returns correct result. tehre way configure return type of query inside namedquery?
try removing list generic so:
public list findall() { return list(namedquery("com.example.findall")); }
it seems cast list of strings , can use generics further chain.
Comments
Post a Comment