-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate save object with SYSDATE
PostPosted: Wed Mar 07, 2007 6:42 am 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
Hibernate version: 3.2.2

I have a situation where I have a table like this

create table User(
id NUMBER(2) PRIMARY KEY,
name VARCHAR2(10),
date_logged DATE);


I can update, insert using Native SQL with Hibernate but how would one
update the User table with SYSDATE value.

User user = (User)session.load(User.class, new Long(10));
//is there a way to set the date logged to sysdate
//I do not want to use Timestamp from Java because the App Server and DB are in separate machine and DB server's time is the trusted time.

user.setDateLogged(..);

I guess what I wanted to know is whether I can use SYSDATE when I am using session.saveOrUpdate()

What I do not prefer to do to solve this:

1. disable this column in mapping file for update, insert and create a update trigger in oracle side

2. use Native SQL/HQL

3. sql timestamp because DB time != App server time

Please reply with any suggestions.


I found this tag

<timestamp name="dateLogged" column="date_logged" source="db"/>

But do we still need to set java.sql.Timestamp
in java code.

user.setDateLogged(new Timestamp(System.currentTimeMillis());

If so,
new Timestamp(System.currentTimeMillis() is redundant

it would be better to have support for DB side keywords/functions


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 7:16 pm 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
HIbernate DTD only supports a max of one timestamp per mapping.

What of the case where there is a class with more than 1 date field. Is that the restriction of trying to save or update Hibernate Mapped Java Objects.


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