-->
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.  [ 4 posts ] 
Author Message
 Post subject: Date/Time format
PostPosted: Wed Jul 07, 2004 1:13 pm 
Newbie

Joined: Wed Jul 07, 2004 12:44 pm
Posts: 2
Hello,

Look the following code:

Java class

Code:
public class Carga
{
   private long id;
   private Date dtFaturamento;
...
...
   get's
   set's
}


Hibernate mapping

Code:
<hibernate-mapping>
    <class name="com.Carga">
        <id name="id" type="long">
   <generator class="native"/>
      </id>
    <property name="dtFaturamento" type="date"/>
</hibernate-mapping>


Struts - Web Tier (Jsp)

Code:
<bean:write name="carga" property="dtFaturamento" format="dd/MM/yy HH:mm"/>


Result

21/06/04 00:00

Using SQLPLUS (Oracle 9.2)

Code:
SELECT TO_CHAR(DTFATURAMENTO,'DD/MM/YY HH:MI') FROM CARGAS;


Result
TO_CHAR(DTFATURAMENTO)
--------------
21/06/04 04:56

How can I get Date/Time format using Hibernate?

Is it possible to define what format I need to get in <property> TAG
Something like this

Code:
<property name="dtFaturamento" type="date" format="dd/mm/yy hh:mm"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Dates and times in Java and Oracle don't work like that. There is no "format", just a Date object with format-independent date and time information. The same is true for Oracle date/time data types.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 1:33 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
If you're having trouble with the time's always being 00:00:00, ie only getting the date, change the property type from date to timestamp.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 1:58 pm 
Newbie

Joined: Wed Jul 07, 2004 12:44 pm
Posts: 2
Myk wrote:
If you're having trouble with the time's always being 00:00:00, ie only getting the date, change the property type from date to timestamp.


Thanks a lot..

It solved my problem...


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

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.