Hello I am using dropwizard for my 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 FROM Person p"
)
})
@JsonProperty
String name;
But When I try to access the resource it always fails saying that in the DAO class the method 'findAll' should return a List<Person>
instead of List<String>
. What am I missing? I checked the query with teh database and it returns the correct result. Is tehre a way to configure the return type of the query inside the namedQuery?