I've been digging through the hibernate source files trying to see how this can be handled. Somebody with more experience may correct me if I'm wrong, but it appears that the Hibernate.TIMESTAMP.nullSafeSet method invoked by PersistentLocalDateTime eventually calls org.hibernate.type.TimestampType.set(PreparedStatement st, Object value, int index), where value is either a java.sql.Timestamp, or an object castable to java.util.Date. This method calls st.setTimestamp(int index, Timestamp x).
Is it possible that this can be fixed by extending org.hibernate.types.TimestampType, and overriding the set method so that it instead calls st.setTimestamp(int index, Timestamp x, Calendar cal), using the Calendar to relate the time zone to use? On Thu, Mar 12, 2009 at 6:56 PM, Stephen Colebourne <scolebou...@joda.org> wrote: > The conversion from LocalDateTime to the database form is going via > DateTime, which is using the time zone. > > Ideally PersistentLocalDateTime should handle this, although exactly > what it should do is open to question. > > Stephen > > > D.M. wrote: >> When attempting to save a LocalDateTime to the database, I am >> receiving an error (included below). My database is Oracle 10g, in >> UTC. My java client is 1.6+, and is running in U.S. Central time >> zone. The time which fails to insert is LocalDateTime(2008,3,9,2,30). >> This time, in the local time zone of the java client, exists in the >> DST cutover where 2:00 becomes 3:00. When toDateTime() is called from >> within PersistentLocalDateTime.nullSafeSet(), the instant cannot be >> created because that instant does not exist in the U.S. Central time >> zone. >> >> So, is this behaving as intended, or is it a bug? The description of >> LocalDateTime from the javadoc is "a datetime without a time zone". >> Is there an additional implication (as the name of the class would >> seem to indicate) that the LocalDateTime occurs in the local time zone >> of the client that creates it? Or should a client be able to save a >> LocalDateTime object to the database that represents a local time >> somewhere other than the client's default time zone? >> >> The error is: >> java.lang.IllegalArgumentException: Illegal instant due to time zone >> offset transition: 2008-03-09T08:30:00.000 >> at >> org.joda.time.chrono.ZonedChronology.localToUTC(ZonedChronology.java:143) >> at >> org.joda.time.chrono.ZonedChronology.getDateTimeMillis(ZonedChronology.java:119) >> at >> org.joda.time.chrono.AssembledChronology.getDateTimeMillis(AssembledChronology.java:133) >> at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:254) >> at org.joda.time.DateTime.<init>(DateTime.java:293) >> at org.joda.time.LocalDateTime.toDateTime(LocalDateTime.java:634) >> at org.joda.time.LocalDateTime.toDateTime(LocalDateTime.java:619) >> at >> org.joda.time.contrib.hibernate.PersistentLocalDateTime.nullSafeSet(PersistentLocalDateTime.java:99) >> at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:146) >> at >> org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1997) >> at >> org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2243) >> at >> org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660) >> at >> org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56) >> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250) >> at >> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234) >> at >> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) >> at >> org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) >> at >> org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) >> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) >> at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) >> at >> org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) >> >> ------------------------------------------------------------------------------ >> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are >> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and >> easily build your RIAs with Flex Builder, the Eclipse(TM)based development >> software that enables intelligent coding and step-through debugging. >> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/joda-interest >> > > ------------------------------------------------------------------------------ > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest