Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate - createQuery not fetching timestamp
    primarykey
    data
    text
    <p>Envrionment: Java, Hibernate JPA provider, JPA, Oracle DB</p> <p>I am trying to create a native query to fetch the data from the Oracle DB. One of the columns is a date column. The date is fetched, but the timestamp is coming out as 00:00:00. However, through an SQL browser, I can see the date and the time. How do I fetch the resultList along with the time?</p> <pre><code>org.hibernate.Query query = ((HibernateEntityManager) entityManager).getSession(). createSQLQuery(NATIVE_QUERY).setResultTransformer(org.hibernate.transform.Transformers.ALIAS_TO_ENTITY_MAP); query.setString(0, accountNumber);; query.setTimestamp(1, startDate).setTimestamp(2, endTime); query.setTimestamp(3, startDate).setTimestamp(4,endTime); List resultList = query.list(); </code></pre> <p>The query itself (in the code above - NATIVE_QUERY) is a normal SQL query for - "Get me all user names and txn time within a given date range whether it is a new transaction or something that has changed in some form". </p> <p><strong>select u.first_name as firstName, u.last_name as lastName, tx.start_time as txnTime from user u, transaction tx where tx.user_id=u.user_id and tx.account_number=? and (tx.start_time > ? and tx.start_time &lt; ? or tx.change_time > ? and tx.change_time &lt; ?)</strong></p> <pre><code>for(Object listItem : resultList){ Map map = (Map) listItem; Date txnTime = (Date)map.get("txnTime".toUpperCase()); //--------&gt; NOT FETCHING THE TIME. I get the time as 00:00:00 } </code></pre> <p>The domain model is very simple</p> <pre><code> @Entity @Table(name="TRANSACTION") @org.hibernate.annotations.Entity( dynamicUpdate = true ) public class Transaction{ @Id @SequenceGenerator(name="txn_gen", sequenceName="TXN_S") @GeneratedValue(generator="txn_gen") @Column(name="TXN_ID") private Long txnId; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="USER_ID", nullable=false) private User user; @Column(name="START_TIME", nullable=false) @Temporal(TemporalType.TIMESTAMP) private java.util.Date startTime; @Column(name="CHANGE_TIME") @Temporal(TemporalType.TIMESTAMP) private java.util.Date changeTime; } @Entity @Table(name="USER") @org.hibernate.annotations.Entity( dynamicUpdate = true ) public class User { @Id @SequenceGenerator(name = "user_gen", sequenceName = "USER_S") @GeneratedValue(generator = "user_gen") @Column(name="USER_ID") private Long userId; @Column(length=500, name="FIRST_NAME") private String firstName; @Column(length=500, name="LAST_NAME") private String lastName; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload