-->
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: Set timestamp type from native sql named query
PostPosted: Thu May 19, 2016 8:10 am 
Beginner
Beginner

Joined: Tue Mar 13, 2007 9:46 am
Posts: 20
I have a named query:

Code:
   <named-native-query name="mynamednativesqlquery">
      <query>
         <![CDATA[
            select a_string, b_string, c_timestamp from table_a
        ]]>
        </query>
   </named-native-query>


Then some code to execute:

Code:
      Query query = entityManager   .createNamedQuery("mynamednativesqlquery");

                for (Object obj : query.getResultList()) {

                     value_a_string = (String) ((Object[]) obj)[0];
                     value_b_string = (String) ((Object[]) obj)[1];
                     value_c_timestamp = (Timestamp) ((Object[]) obj)[2];
                }



When I run this, it casts an exception saying it cannot convert from String to Timestamp (value_c_timestamp).

How can I tell Hibernate that ((Object[]) obj)[2] actually is a timestamp column in the database?


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.