File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes how to insert a current date into the database table ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "how to insert a current date into the database table ?" Watch "how to insert a current date into the database table ?" New topic
Author

how to insert a current date into the database table ?

shyam ji gautam
Ranch Hand

Joined: Sep 17, 2011
Posts: 48
dear all

i am new to hybernate . i have one table called user_maintenance . in which there is one colunm called lastlogin date . i set the default value for this colunm using hbm file like

<property name="lastLogin" formula="(select sysdate from dual)" type="date" insert="false" >
<column name="LAST_LOGIN" length="7">
<comment>Last successful login date</comment>
</column>
</property>

but when i check using following query
select LAST_LOGIN from usermaintenance where user_id = 'shyam' ;
on the database command prompt it shows nothings means empty colunm why?


i want that this sysdate is also automatically insert into the database table (user_maintenance) for colunm LAST_LOGIN for particular user_id(shyam) when particular user_id will login into the system.

any suggestion please?
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
The easy way to create a new Date object in the Java code and set it in your persistent field. There is no need for a Hibernate formula for that.


SCJP 5 , SCWCD 5, SCEA 5
pravin kalbhor
Greenhorn

Joined: Oct 11, 2010
Posts: 2
better you can make that column to take default value at database level...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to insert a current date into the database table ?
 
Similar Threads
what is the length of the Date?
Association references unmapped class exception with hibernate
what i will use in hbm when we use sequence at backend side ?
save entity with SYSDATE
how to insert a current date into the databse colunm using hybernate ?