Hi Michael,
I've almost finished my refactoring and I've run into a hbm2ddl problem
that I have a workaround for, but I'm still curious about why it's
happening...
Michael Horwitz wrote:
On 12/10/07, *Rob Hills* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Hi Michael,
Michael Horwitz wrote:
<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
I found the latest version of joda-time is now 1.5 (in fact 1.5.1) so
I'm using that - it includes a new bit of functionality I already can't
live without ;-)
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")
I did the above virtually verbatim (just changed the package name to be
the same as my model package).
My problem is that when I try and run the maven hibernate3:hbm2ddl goal,
I get errors like this:
Could not determine type for: JodaLocalTime, for columns:
[org.hibernate.mapping.Column(start_time)]
for each of the columns I've defined a joda type for.
The workaround I've found is to simply replace the
@Type(type="JodaDateTime")
with the full classname, like this:
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
However, as I mentioned before, I'm curious to discover why the TypeDefs
in the package-info.java file aren't working. FWIW, I've tried running
this goal both from within Eclipse and from the command line in case
there was some flaw in my Eclipse Maven plugin, but the same thing happens.
Any thoughts?
Rob Hills
Waikiki, Western Australia
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]