-->
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.  [ 3 posts ] 
Author Message
 Post subject: Dates at Hibernate
PostPosted: Tue Oct 10, 2006 12:58 am 
Newbie

Joined: Tue Oct 10, 2006 12:42 am
Posts: 2
Hibernate version:3.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="br.com.bacarin.pauliweb.to">
<class
name="Search"
table="SEARCH"
>
<meta attribute="sync-DAO">false</meta>
<id
name="id"
type="integer"
column="SEARCH_ID"
>
<generator class="increment"/>
</id>

<property
name="searchDate"
column="SEARCH_DATE"
type="timestamp"
not-null="true"
length="16"
/>
<property
name="searchSuccess"
column="SEARCH_SUCCESS"
type="boolean"
not-null="true"
length="1"
/>
<property
name="searchQuantity"
column="SEARCH_QUANTITY"
type="integer"
not-null="true"
length="5"
/>
<many-to-one
name="Sentence"
column="SENTENCE_ID"
class="Sentence"
not-null="true"
>
</many-to-one>


</class>
</hibernate-mapping>


Name and version of the database you are using:SQL Server 2000 Service Pack 4

The generated SQL (show_sql=true):
insert into SEARCH (SEARCH_DATE, SEARCH_SUCCESS, SEARCH_QUANTITY, SENTENCE_ID, SEARCH_ID) values (?, ?, ?, ?, ?)
Hibernate: insert into SEARCH (SEARCH_DATE, SEARCH_SUCCESS, SEARCH_QUANTITY, SENTENCE_ID, SEARCH_ID) values (?, ?, ?, ?, ?)
20875 [main] DEBUG org.hibernate.type.TimestampType - binding '2006-10-09 00:00:00' to parameter: 1
20875 [main] DEBUG org.hibernate.type.BooleanType - binding 'false' to parameter: 2
20875 [main] DEBUG org.hibernate.type.IntegerType - binding '1' to parameter: 3
20875 [main] DEBUG org.hibernate.type.IntegerType - binding '1' to parameter: 4
20875 [main] DEBUG org.hibernate.type.IntegerType - binding '1' to parameter: 5


Hello guys! I have problems with dates in the Hibernate 3.1.
My database is the SQL Server 2000, the date format in the database is (Java SimpleDateFormat notation) "yyyy-dd-MM HH:mm:ss", I´m using the following code to set the date:
Code:
private Date getDate() {
      Locale locale = Locale.US;
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss",locale);
     
      Calendar calendar = formatter.getCalendar();
      calendar.setTimeInMillis(System.currentTimeMillis());
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      return calendar.getTime();
   }

But when I observe in the debug the date goes on the format:"yyyy-MM-dd HH:mm:ss". The Hibernate makes the conversion automatically or I must do the formatting of the date ? In the mapping I tried java.uitl.Date and date, but without effects.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 1:17 am 
Beginner
Beginner

Joined: Thu Oct 06, 2005 8:14 pm
Posts: 23
From my last expt it returns time stamp
do a getclass it should be showing you timestmp
rather than util.date
Priya


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 10:25 am 
Newbie

Joined: Tue Oct 10, 2006 12:42 am
Posts: 2
I´m not in fornt of the code now, but can you explain better your answer please?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.