-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Placeholder in NamedNativeQuery
PostPosted: Thu Mar 18, 2010 2:30 pm 
Newbie

Joined: Thu Jul 17, 2008 10:27 am
Posts: 5
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


Top
 Profile  
 
 Post subject: Re: Placeholder in NamedNativeQuery
PostPosted: Fri Mar 19, 2010 2:59 pm 
Newbie

Joined: Fri Mar 19, 2010 2:37 pm
Posts: 5
Try keeping your native query in side the hbm mapping file.

Under <sql-query> with return tags.


When the hql is printed on the log it will not show the value, instead the place holder will be shown.

_________________
Venod Raveendran
Architect-Technology
[color=#BF4040]Congizant Technology Solutions[/color]


Top
 Profile  
 
 Post subject: Re: Placeholder in NamedNativeQuery
PostPosted: Mon Mar 22, 2010 6:43 am 
Newbie

Joined: Thu Jul 17, 2008 10:27 am
Posts: 5
Hi venodrg,

thanks for your reply :)
My problem suddenly fanished, but I don't know how... It looks the same as the one I posted but now it seems to work...

But I will try what you described. It would be extremely helpful to see the SQL without placeholder.

Thanks,
arres


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.