From 3e73948dae900e6d63030e1bc1bf5ac40e88e361 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 23 Mar 2015 21:02:45 -0500 Subject: [PATCH] HHH-7375 - TimeZone of Calendar objects should be used in binding to JDBC statements --- .../type/descriptor/sql/DateTypeDescriptor.java | 9 ++++++++- .../type/descriptor/sql/TimeTypeDescriptor.java | 10 +++++++++- .../type/descriptor/sql/TimestampTypeDescriptor.java | 9 ++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java index 19c1eef20a..28df773de3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java @@ -29,6 +29,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Calendar; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; @@ -61,7 +62,13 @@ public class DateTypeDescriptor implements SqlTypeDescriptor { return new BasicBinder( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setDate( index, javaTypeDescriptor.unwrap( value, Date.class, options ) ); + final Date date = javaTypeDescriptor.unwrap( value, Date.class, options ); + if ( value instanceof Calendar ) { + st.setDate( index, date, (Calendar) value ); + } + else { + st.setDate( index, date ); + } } }; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java index b21c71fd2c..9764d940e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java @@ -24,11 +24,13 @@ package org.hibernate.type.descriptor.sql; import java.sql.CallableStatement; +import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; import java.sql.Types; +import java.util.Calendar; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; @@ -61,7 +63,13 @@ public class TimeTypeDescriptor implements SqlTypeDescriptor { return new BasicBinder( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setTime( index, javaTypeDescriptor.unwrap( value, Time.class, options ) ); + final Time time = javaTypeDescriptor.unwrap( value, Time.class, options ); + if ( value instanceof Calendar ) { + st.setTime( index, time, (Calendar) value ); + } + else { + st.setTime( index, time ); + } } }; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java index 5ece122c57..2db01a8232 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java @@ -29,6 +29,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; +import java.util.Calendar; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; @@ -61,7 +62,13 @@ public class TimestampTypeDescriptor implements SqlTypeDescriptor { return new BasicBinder( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setTimestamp( index, javaTypeDescriptor.unwrap( value, Timestamp.class, options ) ); + final Timestamp timestamp = javaTypeDescriptor.unwrap( value, Timestamp.class, options ); + if ( value instanceof Calendar ) { + st.setTimestamp( index, timestamp, (Calendar) value ); + } + else { + st.setTimestamp( index, timestamp ); + } } }; }