@Temporal(TemporalType.DATE) with Oracle 12

后端 未结 1 1893
悲&欢浪女
悲&欢浪女 2021-02-06 09:16

In our DB we have multiple entities with Date fields. Oracle sees every date as the same, with a date and a time part. JPA entities however distinguish via the annotaton @Tempor

相关标签:
1条回答
  • 2021-02-06 10:04

    We have conntacted the Oracle Support and they replied as follows (unfortunately I'm not able to provide link to the answer because an Oracle Support Account is needed):

    The new behaviour works as intended:

    In JDBC 12.1.0.1, getDate and setDate do not truncate the time component of the date. This behavior is different to JDBC 11.2.0.X, where the time component is truncated. As per bug 14389749, 17228297 this change is deliberate and the 12c driver's behavior is correct.

    The workarounds provided work for me:

    Workaround #1: Modify application to not insert the time component (e.g. with a static UtilMethod)

    public static Date truncateTime(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }

    Workaround #2: Download and apply patch 19297927 from MOS: (My Oracle Support)

    1. Click on Patches & Updates tab.
    2. Enter the above patch number and Click on Search.
    3. Click on the patch number corresponds to your platform from the list
    4. Click on Download button to download the patch.
    5. Read any applicable notes before downloading, then click the Download button.

    After patching replace ojdb7.jar in %Oracle_Home%\oracle_common\modules\oracle.jdbc_12.1.0 and add -Doracle.jdbc.DateZeroTime=true to your JVM Arguments

    0 讨论(0)
提交回复
热议问题