Hi all,
I am new to Hiberante and I want to migrate an old OJB application to Hibernate. And until now I was more or less successful. But now I have an statistic query I want to migrate. To do this I use the NamedNativeQuery.
This is my Entity: [code] @Entity @SqlResultSetMapping( name="statistic", entities=@EntityResult(entityClass= Statistic.class, fields = { @FieldResult(name="id", column = "id"), @FieldResult(name="createtime", column = "createtime"), @FieldResult(name="quantity", column = "quantity") }) ) @NamedNativeQuery( name = "statisticSearch", query = "SELECT o.id as id, substr(s.createdate, 1, 4) AS createtime, s.status, count(*) as quantity" + " FROM order AS o" + " JOIN state AS s ON o.id = s.refid" + " WHERE substr(s.createdate, 1, 4) > '2000'" + " AND o.id = ?" + " GROUP BY o.id, substr(s.createdate, 1, 4), s.status" + " ORDER BY o.id, substr(s.createdate, 1, 4), s.status", resultSetMapping = "statistic") public class Statistic implements Serializable { .... [/code]
And this is how I want it to call: [code] public List<Statistic> getStatistic(Integer id) { Query query = em.createNativeQuery("statisticSearch"); query.setParameter(1, id);
List<Statistic> result = query.getResultList();
return result; } [/code]
When I execute this code, the log shows, that the placeholder "?" is not replaced. The same happens with something like ":id" and query.setParameter("id", id);
And I also used beside "em.createNativeQuery" the "em.createNamedQuery" method.
If I don't use a placeholder everything works fine.
Does someone of you know how I get my code working?
It would be very nice, if someone could help me, all the best,
arres
|