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.  [ 1 post ] 
Author Message
 Post subject: Return String from CHAR(x) column without mapping properties
PostPosted: Mon Jun 16, 2008 5:20 pm 
Newbie

Joined: Mon Jun 16, 2008 4:53 pm
Posts: 1
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:


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

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.