Whoa!  Glad I asked!

Seriously, thanks for the detail, it would have taken me a lot of time to work all that out from scratch. The tip about package-info.java was especially good, I've not seen one of those animals before. Eclipse didn't like the name much either, as soon as I typed in the hyphen, but it was happy again when I typed the last character.

For anyone else following this thread, who hasn't seen package-info.java before, there's a bit about it about two-thirds of the way down this page:
http://java.sun.com/docs/books/jls/third_edition/html/packages.html

Your details below seem like they'd make a useful tutorial or howto on the AppFuse site.

Michael Horwitz wrote:
On 12/10/07, *Rob Hills* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi Michael,

    Michael Horwitz wrote:
    > On 12/10/07, *Rob Hills* < [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
    > <mailto:[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")

Cheers,

Rob Hills
Waikiki, Western Australia

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to