[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3925) Single quote in Oracle native query incorrectly maps to java Character instead of java String
andrew zimmer (JIRA)
noreply at atlassian.com
Fri May 22 11:35:13 EDT 2009
Single quote in Oracle native query incorrectly maps to java Character instead of java String
---------------------------------------------------------------------------------------------
Key: HHH-3925
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3925
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.2
Reporter: andrew zimmer
Hi Folks,
This little snippet results in a ClassCastException because Hibernate thinks that the single quote in my native query in an Oracle database should be mapped to a Character. It should map to a String.
Query q = em.createNativeQuery("select 'fuz','buz' from dual");
List<Object[]> rows = q.getResultList();
System.out.println("Value: " + rows.iterator().next()[0]);
System.out.println((String)(rows.iterator().next()[0]));
The above throws java.lang.ClassCastException: java.lang.Character.
I have figured out that using a bind variable (example below) instead does the right thing, but this seriously impairs my ability to write a plain SQL String in one method and then pass it into a general purpose method that would do a simple EntityManager.createNativeQuery().getResultList(). The general purpose "execute this piece of SQL for me" won't work because it has to be aware of the bind variables, which is exactly what I"m trying to avoid.
Query q = em.createNativeQuery("select :v1,'buz' from dual");
q.setParameter("v1","fuz");
List<Object[]> rows = q.getResultList();
System.out.println("Value: " + rows.iterator().next()[0]);
System.out.println((String)(rows.iterator().next()[0]));
regards,
andrew
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list