简体   繁体   中英

TimestampType set override error

I am trying to create my own Hibernate mapping to read and write UTC Timestamps to DB with Hibernate, so I am extending the Hibernate TimestampType class as shown below, but I always get the following error. So can someone please help by telling me what I am doing wrong here? Thanks for your time.

Multiple markers at this line - The method set(PreparedStatement, Object, int) of type UTCTimestampType must override or implement a supertype method - Name clash: The method set(PreparedStatement, Object, int) of type UTCTimestampType has the same erasure as set(PreparedStatement, T, int) of type AbstractSingleColumnStandardBasicType but does not override it

public class UTCTimestampType extends org.hibernate.type.TimestampType{

        @Override
        public Object get(ResultSet rs, String name) throws SQLException {
            return rs.getTimestamp(name, createUTCCalendar());
        }

        private static Calendar createUTCCalendar() {
            final Calendar c = Calendar.getInstance();
            c.setTimeZone(new SimpleTimeZone(0, "UTC"));
            return c;
        }

        @Override
        public void set(PreparedStatement st, Object value, int index)
                    throws SQLException{
            Timestamp ts;
            if (value instanceof Timestamp) {
                ts = (Timestamp) value;
            } else {
                ts = new Timestamp(((java.util.Date)value).getTime());
            }
            st.setTimestamp(index, ts, createUTCCalendar());
        }   
}

Take a look at the Java Doc for TimestampType:

TimestampType it extends

AbstractSingleColumnStandardBasicType<Date>

The method signature is set(PreparedStatement st, T value, int index) not with Object

Try:

@Override
        public void set(PreparedStatement st, Date value, int index)
                    throws SQLException{...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM