当Hibernate将Java Calendar对象写入SQL
TIMESTAMP列时,它将日期,计算机日期或Calendar对象(或其他日期)中指定的日期调整到哪个时区?
Hiberante
3.x在
CalendarType(请参阅HB-1006)中使用以下内容:
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { final Calendar cal = (Calendar) value; //st.setTimestamp( index, new Timestamp( cal.getTimeInMillis() ), cal ); //JDK 1.5 only st.setTimestamp( index, new Timestamp( cal.getTime().getTime() ), cal );}因此,Hibernate使用
PreparedStatement#setTimestamp(int, Timestamp,Calendar)哪个使用日历的时区。
当Hibernate将TIMESTAMP读入日历对象时,它将日期转换到哪个时区?
好了,再次让我们看一下这个
CalendarType类:
public Object get(ResultSet rs, String name) throws HibernateException, SQLException { Timestamp ts = rs.getTimestamp(name); if (ts!=null) { Calendar cal = new GregorianCalendar(); if ( Environment.jvmHasTimestampBug() ) { cal.setTime( new Date( ts.getTime() + ts.getNanos() / 1000000 ) ); } else { cal.setTime(ts); } return cal; } else { return null; }}因此,Hibernate会 使用 _ 默认时区* _中 _ 的默认时区中_ 的当前时间来 _构造默认
值GregorianCalendar
*_。



