-->
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: How to mapping oracle date with format 'yyyy-mm-dd'
PostPosted: Mon Feb 18, 2008 10:55 am 
Newbie

Joined: Mon Feb 18, 2008 10:44 am
Posts: 10
I use oracle,it has a date column,so I mapping following code
Code:
<hibernate-mapping>
<class name="test.model" table="testTable">
   <property name="createDate" type="java.util.Date">
      <column name="createdate" not-null="false" />
   </property>
  </class>
</hibernate-mapping>


Then I extract data by using following code:
Code:
String sql="from test.model";
List files=this.getHibernateTemplate().find(sql);


I find createDate value contains date+time,I want to extract createDate which only contains 'yyyy-mm-dd' and no time!

I don't know how to do it! Anybody could tell me how to do it? Please give me detail code.
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 11:39 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
User java.util.DateFormat to print the date as per your choice. When you store date type in database, it always stores with date+time. When the date column from Java code, one has to do the formatting.

Even when you issue a direct SQL query, you use to_date function to get the date as per for format.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 3:34 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
A Date column in Oracle always contains hours, minutes and seconds.

It might be usefull though to set these to 0. You can do that using a Calendar Object in java.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 12:16 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Inheritance and custom types from Hibernate Docs says that:

Mapping type-->Java type---->Standard SQL built-in type
Code:
date-->java.util.Date or java.sql.Date DATE-->
time-->java.util.Date or java.sql.Time-->TIME
timestamp-->java.util.Date or java.sql.Timestamp-->TIMESTAMP
calendar-->java.util.Calendar-->TIMESTAMP
calendar_date-->java.util.Calendar-->DATE


Following this you mapping should be
Code:
<hibernate-mapping>
<class name="test.model" table="testTable">
   <property name="createDate" type="date">
      <column name="createdate" not-null="false" />
   </property>
  </class>
</hibernate-mapping>


And the java type for variable createDate is java.util.Date or java.sql.Date. And I believe only date (with out time) is stored in the database.

Thanks


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.