About

Jadira is the home for Sousan and Chris Pheby's open source projects. These are reusable open source Java modules that provide first class solutions using the most effective current JEE technologies.

Search
Tag Cloud
...
Login

Jadira Support > Hibernate and LocalDate - wierd bug introduced in 3.1.0.CR4

I ran into an interesting bug with LocalDate in 3.1.0.CR4 and up (tested up to CR8). I initially thought this was a problem with timezone offsets but was able to prove it wasn't. We have a MySQL table that has 2 date fields and one datetime. In 3.1.0.CR3, we run a query that pulls that data back into an entity and everything is correct - all 3 dates match, and there is no TZ problem.

If I run the same test in CR4, one of the LocalDate fields is offset back 1 day, the other LocalDate and DateTime type columns were fine.. In the examples look at the startDate field....


IN CR3: Note that the startDate from the query result matches the entity dumped to the log.

2013-07-18 10:05:29.731 [main] TRACE org.hibernate.internal.SessionImpl - SQL query: SELECT p.* FROM PlanAccessCode p WHERE p.accessCodeId = ? AND p.startDate <= ? AND p.endDate > ?
2013-07-18 10:05:29.738 [main] DEBUG org.hibernate.SQL - SELECT p.* FROM PlanAccessCode p WHERE p.accessCodeId = ? AND p.startDate <= ? AND p.endDate > ?
2013-07-18 10:05:29.738 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtaining JDBC connection

---snip uninteresting stuf.....---

2013-07-18 10:05:29.760 [main] TRACE org.hibernate.loader.Loader - Processing result set
2013-07-18 10:05:29.760 [main] DEBUG org.hibernate.loader.Loader - Result set row: 0
2013-07-18 10:05:29.762 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1] as column [planAccessCodeId]
2013-07-18 10:05:29.763 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:05:29.763 [main] TRACE org.hibernate.loader.Loader - Initializing object from ResultSet: [com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:05:29.767 [main] TRACE o.h.p.entity.AbstractEntityPersister - Hydrating entity: [com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:05:29.767 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [400] as column [accessCodeId]
2013-07-18 10:05:29.767 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2012-09-30] as column [endDate]
2013-07-18 10:05:29.781 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2013-07-18 09:45:19.0] as column [lastUpdated]
2013-07-18 10:05:29.781 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1000] as column [planId]
2013-07-18 10:05:29.781 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1bae2dd58a5728bce4] as column [salesforceId]
2013-07-18 10:05:29.781 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2012-03-04] as column [startDate]
2013-07-18 10:05:29.782 [main] TRACE org.hibernate.loader.Loader - Done processing result set (1 rows)

-- snip more hibernate connection stuff --

2013-07-18 10:05:29.789 [main] WARN c.r.b.r.p.PlanAccessCodeRepositoryTest - PlanAccessCode is: com.readytalk.billing.data.jpa.PlanAccessCode@749b475a[
planAccessCodeId=1
accessCodeId=400
planId=1000
endDate=2012-09-30
lastUpdated=2013-07-18T09:45:19.000-06:00
salesforceId=1bae2dd58a5728bce4
startDate=2012-03-04
]


In CR4, the startDate in the Entity doesn't match what's returned from the DB..

2013-07-18 10:25:35.685 [main] TRACE org.hibernate.internal.SessionImpl - SQL query: SELECT p.* FROM PlanAccessCode p WHERE p.accessCodeId = ? AND p.startDate <= ? AND p.endDate > ?
2013-07-18 10:25:35.691 [main] DEBUG org.hibernate.SQL - SELECT p.* FROM PlanAccessCode p WHERE p.accessCodeId = ? AND p.startDate <= ? AND p.endDate > ?

-- snip uninteresting hibernate logging.... --

2013-07-18 10:25:35.713 [main] TRACE org.hibernate.loader.Loader - Processing result set
2013-07-18 10:25:35.713 [main] DEBUG org.hibernate.loader.Loader - Result set row: 0
2013-07-18 10:25:35.715 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1] as column [planAccessCodeId]
2013-07-18 10:25:35.715 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:25:35.715 [main] TRACE org.hibernate.loader.Loader - Initializing object from ResultSet: [com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:25:35.719 [main] TRACE o.h.p.entity.AbstractEntityPersister - Hydrating entity: [com.readytalk.billing.data.jpa.PlanAccessCode#1]
2013-07-18 10:25:35.719 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [400] as column [accessCodeId]
2013-07-18 10:25:35.719 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2012-09-30] as column [endDate]
2013-07-18 10:25:35.722 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2013-07-18 09:45:19.0] as column [lastUpdated]
2013-07-18 10:25:35.722 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1000] as column [planId]
2013-07-18 10:25:35.723 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [1bae2dd58a5728bce4] as column [salesforceId]
2013-07-18 10:25:35.723 [main] TRACE o.h.t.descriptor.sql.BasicExtractor - Found [2012-03-04] as column [startDate]

-- snip hibernate logging --

2013-07-18 10:25:35.733 [main] WARN c.r.b.r.p.PlanAccessCodeRepositoryTest - PlanAccessCode is: com.readytalk.billing.data.jpa.PlanAccessCode@2fc9fc38[
planAccessCodeId=1
accessCodeId=400
planId=1000
endDate=2012-09-30
lastUpdated=2013-07-18T09:45:19.000-06:00
salesforceId=1bae2dd58a5728bce4
startDate=2012-03-03
]

Using MySQL 5.6 as db, w/ latest mysql driver, C3P0, Hibernate 4.2.3, and Joda 2.2

July 18, 2013 | Unregistered CommenterMike

Your issue should be fixed in the current release, 3.1.0.GA. But bear in mind that with MySQL you need to specify the JDBC connection parameter 'useLegacyDatetimeCode=false'.

March 11, 2014 | Registered CommenterChris