[jboss-user] [EJB 3.0] - Problem with native query
TerRamekh
do-not-reply at jboss.com
Tue Aug 22 05:48:01 EDT 2006
Hello!
I have experienced a problem using native query for selecting CHAR(3) column from DB.
The code is:
| @Stateless
| public class NtrBean implements NtrRemote
| {
| @PersistenceContext(unitName = "probe")
| EntityManager entityManager;
|
| public String getMeasure(Long tnvedId) throws Exception
| {
| Query getMeasureQuery = entityManager.createNativeQuery("select test from test_table where id = :id");
| getMeasureQuery.setParameter("id", tnvedId);
| try
| {
| return (String)getMeasureQuery.getSingleResult();
| }
| catch(NoResultException ex)
| {
| return null;
| }
| }
| }
|
As a result of executing of the code snippet I get:
| javax.ejb.EJBException: java.lang.ClassCastException: java.lang.Character
|
So, here it is: native query selects CHAR(3) as one Character object. If I have 'her' value in my 'test' column, then I get 'h'.
I couldn't find any reasonable explanation of this. I've tried this on Informix 9.4 and MySQL 5.0 DB's and had the same effect.
When
| Query getMeasureQuery = entityManager.createNativeQuery("select test from test_table where id = :id");
|
is replaced by:
| Query getMeasureQuery = entityManager.createQuery("select ts.test from TestTable as ts where ts.id = :id");
|
everything works just great.
I don't think problem could reside in my DB-Java mappings in standardjbosscmp-jdbc.xm as I've already tried to play with it.
Could anyone help me?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3966637#3966637
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3966637
More information about the jboss-user
mailing list