On 12/10/07, Rob Hills <[EMAIL PROTECTED]> wrote:
>
> Hi Michael,
>
> Michael Horwitz wrote:
> > On 12/10/07, *Rob Hills* <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
> > I use Joda-time everywhere at the moment - complete joy after fighting
> > with java.util.Date and java.util.Calendar - and that includes the
> > places where I am storing dates/times as integers of the forms you
> > mention above. Joda time's conversion to/from any format is a doddle -
> > no more messing around with SimpleDateFormatter. Joda time's timezone
> > manipulations are also a lot more powerful - the library has a
> > LocalDate, LocalTime and LocalDateTime classes which represent the
> > date, time and date time minus timezone, which seems to be exactly
> > what you want?
> You're a smooth salesman ;-) Actually, I've just spent several hours
> wrestling the "store time as a long solution" to the ground, and I've
> not even started on date or datetime yet. I think it's time to break
> out joda-time.
>
> You wouldn't happen to have a snippet handy I could drop into my .pom by
> any chance would you? If it takes more than 30 seconds to find one,
> don't worry, I'm sure I can work it out.
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>${joda-time-hibernate.version}</version>
</dependency>
with joda-time.version = 1.4 and joda-time-hibernate.version = 1.0
To get it all working with Hibernate you will need a package-info.java file
in the same directory as your model classes. Sample included below:
@TypeDefs( { @TypeDef(name = "JodaDateTime", typeClass =
PersistentDateTime.class),
@TypeDef(name = "JodaLocalTime", typeClass =
PersistentLocalTimeAsTime.class),
@TypeDef(name = "JodaLocalDate", typeClass = PersistentLocalDate.class)})
package com.mycompany.model;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.joda.time.contrib.hibernate.PersistentDateTime;
import org.joda.time.contrib.hibernate.PersistentLocalDate;
import org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime;
You may need to add some additional typedefs as required. Once that lot is
in place simply annotate the getter of each Joda-time field with the correct
type, e.g.:
@Type(type = "JodaDateTime")
Mike
Cheers,
>
> Rob Hills
> Waikiki, Western Australia
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>