Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring批处理-元表-Oracle 12C-UTC时区中的条目_Spring_Timezone_Spring Batch_Metadata_Oracle12c - Fatal编程技术网

Spring批处理-元表-Oracle 12C-UTC时区中的条目

Spring批处理-元表-Oracle 12C-UTC时区中的条目,spring,timezone,spring-batch,metadata,oracle12c,Spring,Timezone,Spring Batch,Metadata,Oracle12c,我们将Oracle 12C DB用于Spring批处理应用程序。 系统时区为PST。 但我希望在UTC时区的元表中包含作业和步骤相关的条目。 有什么建议吗?按照最佳实践,将时间预设为UTC被视为最佳实践,为了避免Spring Boot JPA将来出现错误,请在应用程序中使用以下代码。属性文件,显然您可以根据自己的选择修改时区: spring.jpa.properties.hibernate.jdbc.time_zone = UTC 或者,您可以直接将其附加为: spring.datasourc

我们将Oracle 12C DB用于Spring批处理应用程序。 系统时区为PST。 但我希望在UTC时区的元表中包含作业和步骤相关的条目。
有什么建议吗?

按照最佳实践,将时间预设为
UTC
被视为最佳实践,为了避免Spring Boot JPA将来出现错误,请在应用程序中使用以下代码。属性文件,显然您可以根据自己的选择修改时区:

spring.jpa.properties.hibernate.jdbc.time_zone = UTC
或者,您可以直接将其附加为:

spring.datasource.url=jdbc:oracle:thin://localhost:3306/linkedin?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
但要解决这个问题,你有两个选择:

1-
JPA本机查询
选择并强制转换对象数组,例如:

您可以利用oracle功能将PST转换为UTC

select cast(coltime as timestamp) at time zone 'UTC' from ...
JPA存储库:

public interface EmployeeRepository extends JpaRepository<Employee, Long> {
    @Query(value = "select cast(DD.Ch_Status_Validfrom as timestamp) at time zone 'UTC', za.first_name, za.birth_date, ts.salary\n" +
            "from employees za, salaries ts  \n" +
            "where za.emp_no= :id" +
            " LIMIT 10 OFFSET 20"
            ,nativeQuery = true)
    List<Object[]> findWithSalary(@Param("id")Integer id);

}
您的问题与(postgresql)类似吗?您是否尝试过使用带时区的
时间戳
数据类型:,修改Spring Batch for Oracle提供的DDL脚本?
@Component
public class LoaderBootStrap implements CommandLineRunner {

    private final EmployeeRepository employeeRepository;

    @Override
    public void run(String... args) throws Exception {

        List<Object[]> withSalary = employeeRepository.findWithSalary(10001);
    }
}
 private final void demo(){
     ZoneId assiaZone = ZoneId.of("Asia/Singapore");
     ZoneId americaZone = ZoneId.of("America/New_York");

     ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"));

     System.out.println("Current Time As UTC : " + zonedDateTime);
     System.out.println("Current time As America time : " + dateConvertWithZoneId(zonedDateTime, americaZone));
     System.out.println("Current time As Asia time : " + dateConvertWithZoneId(zonedDateTime, assiaZone));
        
}
        
 private final LocalDateTime dateConvertWithZoneId(ZonedDateTime actualDate, ZoneId withZone){

    ZonedDateTime date = actualDate;

    return date.withZoneSameInstant(withZone).toLocalDateTime();

 }