在我的PostgreSQL上,如果我运行该脚本:
show timezone;
它又回来了
Europe/Rome
所以根据这一点,我配置了
spring.jpa.properties.hibernate.jdbc.time_zone: Europe/Rome
我有一个表TestPostgre,它的列datetime_using_instant的数据类型为timestamp.
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Table(name = "test_postgre")
public class TestPostgre {
@Id
@Column(name = "pk", nullable = false)
private String pk;
@Column(name = "datetime_using_instant", nullable = false)
private Instant dateTimeUsingInstant;
}
使用JpaRepository:
@Repository
public interface TestPostgreRepository extends JpaRepository<TestPostgre, String> {
}
当使用DateTimeUsing Instant值2023-10-11T12:30:00Z保存TestPostgre实例时,在PostgreSQL上,该值仍然是2023-10-11 12:30:00.000,但协调世界时和欧洲/罗马之间有2小时的偏移.