HHH-7375 - TimeZone of Calendar objects should be used in binding to JDBC statements

This commit is contained in:
Steve Ebersole 2015-03-23 21:02:45 -05:00
parent 9883d7b11a
commit 3e73948dae
3 changed files with 25 additions and 3 deletions

View File

@ -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<X>( 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 );
}
}
};
}

View File

@ -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<X>( 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 );
}
}
};
}

View File

@ -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<X>( 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 );
}
}
};
}