-->
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.  [ 4 posts ] 
Author Message
 Post subject: JPA scalar native query result mapping
PostPosted: Mon Oct 20, 2008 3:20 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
Hi,

I'm using Hibernate EntityManager API (v3.3.1) for executing a native query that returns a set of integer values, one integer per row.
Hibernate automatically maps the values to BigDecimal type, but I'd like to use Long.
Can I explicitly specify the result type here somehow?


Top
 Profile  
 
 Post subject: Re: JPA scalar native query result mapping
PostPosted: Mon Oct 20, 2008 3:47 pm 
Newbie

Joined: Thu Oct 09, 2008 4:03 pm
Posts: 16
Location: US, Itasca Illinois
Yes, you should be able to because this functionality is supported in core Hibernate. I was able to designate a type:

<sql-query name="BssDailyStat.findByTotalTxMegabytesTopN" >
<return-scalar column="sectorName" type="java.lang.String"/>
<return-scalar column="sectorNbr" type="java.lang.Integer"/>
select statement .....
</sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2008 2:14 am 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
The query is being generated dynamically by the application and I'm using the JPA API.
Any ideas on how I could specify the result type in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2008 10:32 am 
Newbie

Joined: Thu Oct 09, 2008 4:03 pm
Posts: 16
Location: US, Itasca Illinois
Hi,
This thread was in a different forum, but may help.

http://forums.java.net/jive/message.jsp ... eID=250807

Regards,
Lynette


@Stateless(name="ImagesServiceImpl")
public class ImagesServiceImpl implements ImagesService {

@PersistenceContext
EntityManager em;

public Long getNewImageId() {
Query q = em.createNativeQuery(
"SELECT nextval('global_next_image_id_seq') AS ID");
try {
return (Long)((List) q.getSingleResult()).get(0);
}
catch(Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.