-->
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.  [ 3 posts ] 
Author Message
 Post subject: Use a custom Type for setDate() or setTimestamp()?
PostPosted: Sat Sep 13, 2008 12:54 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
I have a large project that's about to switch databases, from Postgres to mysql... I'm planning to store dates in long int columns because of mysql's lack of date precision. Using a custom UserType works fine, but I've found that I now need to call Query.setParameter(String, String, Type) instead of setDate()...

I looked into how to override what type setDate() or setTimestamp() uses.. but I came up empty handed. It appears that the implementations for the types, including the QueryImpl, and SessionImpl classes.. are pretty hard-coded.

Is there a pattern for accomplishing what I'm looking for? I'm definitely a bit surprised, since this is an ORM that supports quite a bit of custom type definition... I'd like not to have to convert the codebase to use the setParameter() method. I'd love to make this change more seamless than that.

Thanks in advance,
Phill


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2008 5:19 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Why not simply use
Code:
query.setParameter(<param name>, <param value>)

where <param value> is your date object - no need to tell the type - Hibernate is clever enough to discover it and use the UserType you defined.

For your info, I've implemented such a user type for dates as you described and I'm passing the parameters to the query as explained above without any problems...

_________________
If you found my post helpful, please rate it! Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2008 5:25 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Thanks.. I didn't know that, actually.. I assumed it might have resulted in the same thing as setDate()...

The challenge I'm having is that I have a team of people used to calling setDate() and I'd like to make this change as seamless as possible.

Since everywhere in our codebase gets Session instances through a HibernateUtil class of ours (like pretty much everyone else who uses Hibernate, I imagine)...

Last night I created Session & Query wrappers that simply delegate all method calls through, massaging the setDate() into setParameter()..

Not sure how I feel about it yet, but it works of course :)


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