-->
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: Support for Date inheritance
PostPosted: Tue Feb 03, 2009 3:47 pm 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
Hi,

I am developing an app where one of my entities needs a more specialized Date object that I've implemented through inheritance.
The problem though, is that Hibernate does not accept it. It throws the following exception on initialization:

Code:
org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property


Has anyone had this same issue?? Has anyone any nice workaroud?
I believe that Hibernate team should make it possible to use subclasses of Date.

Thanks in advance,
Vitor.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 6:44 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Is your specialized Date adding any data, or just behaviour?

i.e. do you need to persist anything different from a plain Date?


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 1:12 am 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
Hi Stephen,

My specialized Date only adds behavior to the application.
It should be stored as a plain Date in the database.

Actually, it doesn't have any behavior at all. I just extend Date class.
I am using it, so that I can use a custom field serializer with GWT. By making this custom Date, I can control the serialization/deserialization process when it finds this specialized class of mine.

In my application, I have two types of dates: one that should use time zones, and another one that shouldn't.

So, when serializing/deserializing the one that shouldn't (my specialized Date), I need control of this process to make the dates equal in both time zones if the server and client have different time zones.

For example, if the client is in eastern US (-5h) and the server is in Germany (+1h). When the client sends a date at 14h, that same date would be 20h in the server. So I would have to decrease 6 hours to make them equal.

Well, I hope you understand the reason why I need a specialized Date class.

Regards,
Vitor.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 6:41 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
You could try having your date field declared as a java.util.Date with the Temporal annotation, then provide accessor methods for GWT to use your customized Date - which would presumable be able to simply decorate the Date.


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 1:16 pm 
Beginner
Beginner

Joined: Mon Sep 01, 2008 9:35 am
Posts: 24
Thanks Stephen,

It worked just fine! I don't know why I didn't think of this before.
Here is how I did it:

Code:
...
private Date date;

public Date getDate() {
    return date;
}

public void setDate(Date date) {
    this.date = new LocalDate(date.getTime());
}
...


Now Hibernate thinks it is a normal Date, and GWT sees it as a LocalDate during serialization/deserialization.

Regards,
Vitor.


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.