-->
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: Register default converters for custom field type
PostPosted: Fri Mar 26, 2010 3:07 pm 
Newbie

Joined: Mon Dec 14, 2009 5:27 pm
Posts: 7
We use Joda Time in the project, and all dates in @Entities are of type org.joda.time.DateTime. We use Joda-Hibernate user types for mapping it to DB.
BUT: I'm tired of declaring the field type on every such date:
Code:
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime actualStartDate;
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime actualEndDate;
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime plannedStartDate;
    ...

From what I've found, I can declare global alias using @TypeDef, than I could make it a bit shorter, e. g.:
Code:
    @Type(type = "persistentDateTime")
    private DateTime actualStartDate;
    @Type(type = "persistentDateTime")
    private DateTime actualEndDate;
    @Type(type = "persistentDateTime")
    private DateTime plannedStartDate;
    ...

But still it's horrendous amount of pointless code. How can I globally tell Hibernate "use this user type converter for fields of that type"? So that I finish with:
Code:
    private DateTime actualStartDate;
    private DateTime actualEndDate;
    private DateTime plannedStartDate;
    ...

I can't find a way to do it... but it's crazy too much to assume it can't be done...


Top
 Profile  
 
 Post subject: Re: Register default converters for custom field type
PostPosted: Mon Mar 29, 2010 1:57 pm 
Newbie

Joined: Mon Dec 14, 2009 5:27 pm
Posts: 7
Does it mean it really can't be done? It's hard to believe... looks like very very basic requirement... I should probably craete a Jira issue about it?


Top
 Profile  
 
 Post subject: Re: Register default converters for custom field type
PostPosted: Mon Sep 26, 2011 3:00 am 
Newbie

Joined: Sun Jan 24, 2010 4:20 pm
Posts: 13
grzegorz wrote:
Does it mean it really can't be done? It's hard to believe... looks like very very basic requirement... I should probably craete a Jira issue about it?


What happended to an active community? Anyone from the Hibernate-team care to comment on this? I agree that this kind of functionality really helps and should be part of the JPA spec (which I think JPA-2.1 actually addresses).


Top
 Profile  
 
 Post subject: Re: Register default converters for custom field type
PostPosted: Tue Jan 17, 2012 7:49 am 
Newbie

Joined: Tue Jan 17, 2012 7:46 am
Posts: 1
still an issue, after two years...

i just don't want to redeclare my joda type on each and every field. there is also the risk some colleague might not be aware of doing this, and then we've got a runtime error, sweet...

BTW: is it really necessary to send me my password in plaintext via mail for the account activation? this really sucks, as i guess this forum is storing my password in cleartext :(


Top
 Profile  
 
 Post subject: Re: Register default converters for custom field type
PostPosted: Sat Apr 28, 2012 7:45 pm 
Newbie

Joined: Sun Jan 24, 2010 4:20 pm
Posts: 13
cpi wrote:
still an issue, after two years...

i just don't want to redeclare my joda type on each and every field. there is also the risk some colleague might not be aware of doing this, and then we've got a runtime error, sweet...

BTW: is it really necessary to send me my password in plaintext via mail for the account activation? this really sucks, as i guess this forum is storing my password in cleartext :(


This is actually possible using Hibernate-4.

Have this in your pom (version 3.0.0.CR1):
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
</dependency>

Set these properties
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="jadira.usertype.databaseZone">jvm</prop>


And you're good:-)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.