Hi everybody,
I'm new with Hibernate so this might be a simple question, but I didn't found the answer in the documentation (maybe because I didn't search correctly :) ).
I am using Hibernate 3 and DB2 database.
I have a table where there are columns defined as CHAR(x). I have created something like this :
Code:
<hibernate-mapping>
<sql-query name="NamedQyery">
select MESSAGE_ID, MESSAGE_TEXT from MESSAGES where MESSAGE_ID = ?
</sql-query>
</hibernate-mapping>
The column MESSAGE_ID is defined as CHAR(1) and MESSAGE_TEXT is defined as CHAR(255).
My java code is :
Code:
try {
Query query=session.getNamedQuery("NamedQuery");
query.setCharacter(0, 'a');
List resultList = query.list();
if (resultList.size() == 0 ) {
//do something here
}
else {
Character ch;
String str;
Object rowResult = resultList.get(0);
Object[] arrayRowResult = (Object[])rowResult;
ch = (Character)arrayRowResult[0];
if ( arrayRowResult[1] != null ) {
str = (String)arrayRowResult[1];
}
else {
str = null;
}
}
}
catch (org.hibernate.HibernateException ex){
//do something here
}
I know this is not a good Hibernate style but I want to use this solution if it's possible.
My problem is that the type of second element in arrayRowResult is Character and the value is the first character of the value in the column MESSAGE_TEXT.
Is there a possibility to use an SqlQuery to return Strings for CHAR(x) columns without using mapping properties in the <hibernate-mappings>? Is there a possibility to change only the java code in my example to have the expected result?
Thanks in advance,
Steven.
Code: