Joda time DateTime incorrectly stores in database

前端 未结 7 1651
青春惊慌失措
青春惊慌失措 2020-12-30 08:18

I\'m storing JodaTime DateTime field to timestamptz column by using org.jadira.usertype:usertype.jodatime:1.9. App server has +4 time

7条回答
  •  囚心锁ツ
    2020-12-30 08:55

    I had resolved this problems by creating other PersistentDateTime extends AbstractVersionableUserType.

    import java.sql.Timestamp;
    
    import org.hibernate.SessionFactory;
    import org.hibernate.usertype.ParameterizedType;
    import org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnDateTimeMapper;
    import org.jadira.usertype.spi.shared.AbstractVersionableUserType;
    import org.jadira.usertype.spi.shared.IntegratorConfiguredType;
    import org.joda.time.DateTime;
    
    public class PersistentDateTime extends AbstractVersionableUserType implements ParameterizedType, IntegratorConfiguredType {
    
    @Override
    public int compare(Object o1, Object o2) {
        return ((DateTime) o1).compareTo((DateTime) o2);
    }
    
    @Override
    public void applyConfiguration(SessionFactory sessionFactory) {
    
        super.applyConfiguration(sessionFactory);
    
        TimestampColumnDateTimeMapper columnMapper = (TimestampColumnDateTimeMapper) getColumnMapper();
        columnMapper.setDatabaseZone(null);
        columnMapper.setJavaZone(null);
    }
    }
    

提交回复
热议问题