-->
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.  [ 6 posts ] 
Author Message
 Post subject: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 5:56 am 
Newbie

Joined: Tue Aug 17, 2010 5:44 am
Posts: 3
Consider Java object has startDate attribute; Oracle Table has start_date field. How to save an object with sysdate(current date and time) value in database table using HIBERNATE?


Top
 Profile  
 
 Post subject: Re: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 6:36 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi 141748,

Could you elaborate the scenario so that more ideas can be shared!

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 7:04 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
141748 wrote:
Consider Java object has startDate attribute; Oracle Table has start_date field. How to save an object with sysdate(current date and time) value in database table using HIBERNATE?


Set them to System.currentTimeMillis() in your program (either right before saving or inside the constructor), use a default value at the database (SYSDATE) or a trigger that fills in SYSDATE if no value is provided externally.


Top
 Profile  
 
 Post subject: Re: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 7:06 am 
Newbie

Joined: Tue Aug 17, 2010 5:44 am
Posts: 3
I am a beginner in Hibernate tech.

I want to insert current date and time( e-g 8/17/2010 5:33:00 PM) in Oracle table.

Table structure
table name - BATCH_Q
job_id number(7);
start_date date;



My Object will be,

public class JobStatusObject{
private long jobId;
private Date startDate;
getters and setters for that
}

Mapping file will be,

<class name="com.test.JobStatusObject" table="BATCH_Q">
<meta attribute="class-description"></meta>
<id name="jobId" type="long" column="JOB_ID" unsaved-value="null">
<generator class="sequence">
<param name="sequence">JOB_ID</param>
</generator>
</id>
<property name="startDate" type="date" column="START_DATE" />
</class>

Client class code

main(){
JobStatusObject obj = new JobStatusObject();
obj.setStartDate(new Date); -- it inserts date alone.
session.save(obj);
}

But it inserts date alone. I want the time also to be inserted along with date field.
I should not use any trigger in database
Could you please provide a solution as how to insert current date and time in oracle table.


Top
 Profile  
 
 Post subject: Re: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 7:12 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You can use TIMESTAMP instead of DATE.


Top
 Profile  
 
 Post subject: Re: Insert current date and time in table
PostPosted: Tue Aug 17, 2010 7:53 am 
Newbie

Joined: Tue Aug 17, 2010 5:44 am
Posts: 3
Hi CDillinger,

Thanks.Changed date to timestamp value. It is working fine now.


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