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.  [ 5 posts ] 
Author Message
 Post subject: Database current DateTime
PostPosted: Tue Dec 07, 2004 5:34 am 
Newbie

Joined: Tue Jun 15, 2004 11:44 am
Posts: 7
Hi all,

We are developing a multi-client (/server) application.
For some reasons we need to have the current date&time on the client side, unfortenately client machines may not be synchronized. As a consequence we are using the database server clock.

Before starting with hibernate, we used to issue queries like:
(Oracle)
Code:
select sysdate from dual

(DB2)
Code:
select current timestamp from one_of_our_table


Like you know it's database dependant, and then I would like to know what is the most elegant way of implementing this using hibernate.

I know that in some cases, hibernate isn't the right answer and the direct jdbc is the best... but what is your opinion?

I forget to say that we don't store this current date&time (at least not always), but use it for processing on the client machine.

Thanks.
Johann


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 5:58 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
Hi.

I think, that you create two named query, and use the Dialect.getDialect(), to know which dialect you're using, and according to the Dialect you execute the correct one.

didn't check it, hope it's right.

Jus.


Top
 Profile  
 
 Post subject: Re: Database current DateTime
PostPosted: Tue Dec 07, 2004 3:59 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 2:46 pm
Posts: 45
Location: Saskatoon SK Canada
You could go for a 'fix' in the database. Create a view that does the query for you. The view could also format the date/time in a consistent way, so if you change databases, your Java/Hibernate code would never know the difference.[/b]

_________________
Maury


Top
 Profile  
 
 Post subject: Re: Database current DateTime
PostPosted: Tue Dec 07, 2004 5:43 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
MjH wrote:
You could go for a 'fix' in the database. Create a view that does the query for you. The view could also format the date/time in a consistent way, so if you change databases, your Java/Hibernate code would never know the difference.[/b]


didn't think about that. great idea.

Jus.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 11:56 am 
Newbie

Joined: Tue Jun 15, 2004 11:44 am
Posts: 7
Issahar wrote:
Hi.

I think, that you create two named query, and use the Dialect.getDialect(), to know which dialect you're using, and according to the Dialect you execute the correct one.

didn't check it, hope it's right.

Jus.


Nice, it could be really easy if there is a way to access this values from the sessionfactory ... i will have a look where it's possible to add this feature at the sessionfactory level.


MjH wrote:
You could go for a 'fix' in the database. Create a view that does the query for you. The view could also format the date/time in a consistent way, so if you change databases, your Java/Hibernate code would never know the difference.[/b]


Could be a solution, but if the view is designed to send back a java.sql.Timestamp, it (java/hibernate mapping) would never change from a database to another.

Thank you for your help.


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