comparing hibernate-mapped dates?
how i map date java vigilant database hibernate? i try opposite approaches, nonetheless i am happy them. why? let me explain issue. i have following category [1] including sure slight i plead following mapping [2]. emanate proceed see, feeling during console output.
false
false
1
-1
1224754335648
1224754335000
thu oct 23 11:32:15 cest 2008
clock@67064
as the dates accurately equal, nonetheless should, tough review but goofing around relapse value gettime
. i also attempted java.sql.date, timestamp date instead timestamp mapping, nonetheless but success.
i awe since final 3 digits 0 hibernate java emanate possess stupidity.
thank reading.
[1]
public category time {
int id;
java.util.date date;
open stationary vacant main(string[] args) {
hibernateutil.init();
hibernateutil.getsessionfactory().getcurrentsession().begintransaction();
time clock = new clock();
clock.date = new java.util.date();
hibernateutil.getsessionfactory().getcurrentsession().saveorupdate(clock);
hibernateutil.getsessionfactory().getcurrentsession().gettransaction().commit();
hibernateutil.getsessionfactory().getcurrentsession().begintransaction();
time fromdbclock = (clock)hibernateutil.getsessionfactory()
.getcurrentsession().get(clock.class, 1);
system.out.println(clock.date.equals(fromdbclock.date));
system.out.println(fromdbclock.date.equals(clock.date));
system.out.println(clock.date.compareto(fromdbclock.date));
system.out.println(fromdbclock.date.compareto(clock.date));
system.out.println(clock.date.gettime());
system.out.println(fromdbclock.date.gettime());
system.out.println(clock.date.tostring());
system.out.println(fromdbclock.tostring());
hibernateutil.getsessionfactory().getcurrentsession().gettransaction().commit();
hibernateutil.end();
}
open int getid() {
relapse id;
}
open vacant setid(int id) {
this.id = id;
}
open java.util.date getdate() {
relapse date;
}
open vacant setdate(java.util.date date) {
this.date = date;
}
}
[2]
<?xml version="1.0"?>
<!doctype hibernate-mapping public
"-//hibernate/hibernate mapping dtd 3.0//en"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="clock" table="clock">
<id name="id" column="clock_id">
<generator class="native"/>
</id>
<property name="date" type="timestamp"/>
</class>
</hibernate-mapping>
Comments
Post a Comment