gpt4 book ai didi

java - TimestampType 设置覆盖错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:54 34 4
gpt4 key购买 nike

我正在尝试创建自己的 Hibernate 映射以使用 Hibernate 将 UTC 时间戳读写到 DB,因此我正在扩展 Hibernate TimestampType 类,如下所示,但我总是收到以下错误。那么有人可以告诉我我在这里做错了什么吗?感谢您的宝贵时间。

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

最佳答案

查看 TimestampType 的 Java 文档:

TimestampType它延伸

AbstractSingleColumnStandardBasicType<Date>

方法签名是 set(PreparedStatement st, T value, int index) 而不是 Object

尝试:

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

关于java - TimestampType 设置覆盖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21462383/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com