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.