Oracle 10 gドライバdateタイプについて時間分秒の問題はありません
一般的なデータベースでは、DATEフィールドは日付のみを表し、日付情報は含まれません.OracleデータベースのDATEデータ型には日付、時刻が含まれます.この問題の処理は、異なるOracle jdbcドライババージョンでは異なります.
最近ORACLE 10 Gを使って、时间のフィールドは需要のため、DATEのタイプに设けて、hibernateがnative SQLで検索することを発见して、时间の分秒を表示することができなくて、もとはJDBCが自动的にdateをjavaにマッピングするのです.sql.Dateなので、時刻分秒情報を遮断します.9 iまたは11 gのドライバを使用する場合は問題ありませんが、Oracle 10 gのJDBCドライバでは、時刻分秒がないことがわかります.Oracle 9では.2以降,内蔵データ型TIMESTAMPを導入した.これを導入したのは、内蔵データ型DATEの最小単位が秒であるためである.DATEの主な問題は,その粒度が2つのイベントのどちらが先に発生するかを十分に区別できないことである.9.2以降、ORACLEはDATEデータ型にTIMESTAMPデータ型を拡張し、すべてのDATEデータ型の年月日分秒の情報と小数秒の情報を含む.DATEタイプをTIMESTAMPタイプに変換したい場合はCAST関数を使用します.oracle 9.2から、内蔵データ型DATEとTIMESTAMPが9 iのJDBCドライバを用いてクエリーを行う際に、DATEがjavaにマッピングされる.sql.Date,TIMESTAMPはjavaにマッピングする.sql.Timestamp.Oracle 11からJDBCドライバは、組み込み型DATEをjavaにマッピングするための復帰を再開します.sql.Timestamp(9.2以前の通り).したがって,時分秒精度の喪失はhibernateに関係なくoracle jdbc駆動の問題である.最善の解決策は、駆動を交換することです.最初に使用する駆動ojdbc 14を試験した.JArを11 gの駆動ojdbc 5に変更する.JAr後;
参照
Simple Data Types
What is going on with DATE and TIMESTAMP?
This section is on simple data types. :-)
Prior to 9.2, the Oracle JDBC drivers mapped the DATE SQL type to java.sql.Timestamp. This made a certain amount of sense because the Oracle DATE SQL type contains both date and time information as does java.sql.Timestamp. The more obvious mapping to java.sql.Date was somewhat problematic as java.sql.Date does not include time information. It was also the case that the RDBMS did not support the TIMESTAMP SQL type, so there was no problem with mapping DATE to Timestamp.
In 9.2 TIMESTAMP support was added to the RDBMS. The difference between DATE and TIMESTAMP is that TIMESTAMP includes nanoseconds and DATE does not. So, beginning in 9.2, DATE is mapped to Date and TIMESTAMP is mapped to Timestamp. Unfortunately if you were relying on DATE values to contain time information, there is a problem.
There are several ways to address this problem in the 9.2 through 10.2 drivers:
Alter your tables to use TIMESTAMP instead of DATE. This is probably rarely possible, but it is the best solution when it is.
Alter your application to use defineColumnType to define the columns as TIMESTAMP rather than DATE. There are problems with this because you really don't want to use defineColumnType unless you have to (see What is defineColumnType and when should I use it?).
Alter you application to use getTimestamp rather than getObject. This is a good solution when possible, however many applications contain generic code that relies on getObject, so it isn't always possible.
Set the V8Compatible connection property. This tells the JDBC drivers to use the old mapping rather than the new one. You can set this flag either as a connection property or a system property. You set the connection property by adding it to the java.util.Properties object passed to DriverManager.getConnection or to OracleDataSource.setConnectionProperties. You set the system property by including a -D option in your java command line.
java -Doracle.jdbc.V8Compatible="true"MyApp
Oracle JDBC 11.1 fixes this problem. Beginning with this release the driver maps SQL DATE columns to java.sql.Timestamp by default. There is no need to set V8Compatible to get the correct mapping. V8Compatible is strongly deprecated. You should not use it at all. If you do set it to true it won't hurt anything, but you should stop using it.
Although it was rarely used that way, V8Compatible existed not to fix the DATE to Date issue but to support compatibility with 8i databases. 8i (and older) databases did not support the TIMESTAMP type. Setting V8Compatible not only caused SQL DATE to be mapped to Timestamp when read from the database, it also caused all Timestamps to be converted to SQL DATE when written to the database. Since 8i is desupported, the 11.1 JDBC drivers do not support this compatibility mode. For this reason V8Compatible is desupported.
As mentioned above, the 11.1 drivers by default convert SQL DATE to Timestamp when reading from the database. This always was the right thing to do and the change in 9i was a mistake. The 11.1 drivers have reverted to the correct behavior. Even if you didn't set V8Compatible in your application you shouldn't see any difference in behavior in most cases. You may notice a difference if you use getObject to read a DATE column. The result will be a Timestamp rather than a Date. Since Timestamp is a subclass of Date this generally isn't a problem. Where you might notice a difference is if you relied on the conversion from DATE to Date to truncate the time component or if you do toString on the value. Otherwise the change should be transparent.
If for some reason your app is very sensitive to this change and you simply must have the 9i-10g behavior, there is a connection property you can set. Set mapDateToTimestamp to false and the driver will revert to the default 9i-10g behavior and map DATE to Date.
構成:
データベース#データベース#
dateをtimestampタイプに設定します.
各ドライバパッケージに存在するBUG:
参照
Driver Result
with classes12.zip at C:\Oracle\Ora81\jdbc\lib, Oracle JDBC Drivers release 8.1.6 OK, no problem found
with "oracle 8.1.7 driver\classes12.zip", oracle 8.1.7 driver OK, no problem found
with "oracle 10i\classes12.jar", oracle 10i driver ID corrputed. Bug
with "oracle9i driver\classes12.jar", oracle 9i driver ID corrputed. Bug
with "oracle 10i\ojdbc14.jar", oracle 10i driver ID corrputed. Bug
with "oracle9i driver\ojdbc14.jar", oracle 9i driver ID corrputed. Bug
最近ORACLE 10 Gを使って、时间のフィールドは需要のため、DATEのタイプに设けて、hibernateがnative SQLで検索することを発见して、时间の分秒を表示することができなくて、もとはJDBCが自动的にdateをjavaにマッピングするのです.sql.Dateなので、時刻分秒情報を遮断します.9 iまたは11 gのドライバを使用する場合は問題ありませんが、Oracle 10 gのJDBCドライバでは、時刻分秒がないことがわかります.Oracle 9では.2以降,内蔵データ型TIMESTAMPを導入した.これを導入したのは、内蔵データ型DATEの最小単位が秒であるためである.DATEの主な問題は,その粒度が2つのイベントのどちらが先に発生するかを十分に区別できないことである.9.2以降、ORACLEはDATEデータ型にTIMESTAMPデータ型を拡張し、すべてのDATEデータ型の年月日分秒の情報と小数秒の情報を含む.DATEタイプをTIMESTAMPタイプに変換したい場合はCAST関数を使用します.oracle 9.2から、内蔵データ型DATEとTIMESTAMPが9 iのJDBCドライバを用いてクエリーを行う際に、DATEがjavaにマッピングされる.sql.Date,TIMESTAMPはjavaにマッピングする.sql.Timestamp.Oracle 11からJDBCドライバは、組み込み型DATEをjavaにマッピングするための復帰を再開します.sql.Timestamp(9.2以前の通り).したがって,時分秒精度の喪失はhibernateに関係なくoracle jdbc駆動の問題である.最善の解決策は、駆動を交換することです.最初に使用する駆動ojdbc 14を試験した.JArを11 gの駆動ojdbc 5に変更する.JAr後;
参照
Simple Data Types
What is going on with DATE and TIMESTAMP?
This section is on simple data types. :-)
Prior to 9.2, the Oracle JDBC drivers mapped the DATE SQL type to java.sql.Timestamp. This made a certain amount of sense because the Oracle DATE SQL type contains both date and time information as does java.sql.Timestamp. The more obvious mapping to java.sql.Date was somewhat problematic as java.sql.Date does not include time information. It was also the case that the RDBMS did not support the TIMESTAMP SQL type, so there was no problem with mapping DATE to Timestamp.
In 9.2 TIMESTAMP support was added to the RDBMS. The difference between DATE and TIMESTAMP is that TIMESTAMP includes nanoseconds and DATE does not. So, beginning in 9.2, DATE is mapped to Date and TIMESTAMP is mapped to Timestamp. Unfortunately if you were relying on DATE values to contain time information, there is a problem.
There are several ways to address this problem in the 9.2 through 10.2 drivers:
Alter your tables to use TIMESTAMP instead of DATE. This is probably rarely possible, but it is the best solution when it is.
Alter your application to use defineColumnType to define the columns as TIMESTAMP rather than DATE. There are problems with this because you really don't want to use defineColumnType unless you have to (see What is defineColumnType and when should I use it?).
Alter you application to use getTimestamp rather than getObject. This is a good solution when possible, however many applications contain generic code that relies on getObject, so it isn't always possible.
Set the V8Compatible connection property. This tells the JDBC drivers to use the old mapping rather than the new one. You can set this flag either as a connection property or a system property. You set the connection property by adding it to the java.util.Properties object passed to DriverManager.getConnection or to OracleDataSource.setConnectionProperties. You set the system property by including a -D option in your java command line.
java -Doracle.jdbc.V8Compatible="true"MyApp
Oracle JDBC 11.1 fixes this problem. Beginning with this release the driver maps SQL DATE columns to java.sql.Timestamp by default. There is no need to set V8Compatible to get the correct mapping. V8Compatible is strongly deprecated. You should not use it at all. If you do set it to true it won't hurt anything, but you should stop using it.
Although it was rarely used that way, V8Compatible existed not to fix the DATE to Date issue but to support compatibility with 8i databases. 8i (and older) databases did not support the TIMESTAMP type. Setting V8Compatible not only caused SQL DATE to be mapped to Timestamp when read from the database, it also caused all Timestamps to be converted to SQL DATE when written to the database. Since 8i is desupported, the 11.1 JDBC drivers do not support this compatibility mode. For this reason V8Compatible is desupported.
As mentioned above, the 11.1 drivers by default convert SQL DATE to Timestamp when reading from the database. This always was the right thing to do and the change in 9i was a mistake. The 11.1 drivers have reverted to the correct behavior. Even if you didn't set V8Compatible in your application you shouldn't see any difference in behavior in most cases. You may notice a difference if you use getObject to read a DATE column. The result will be a Timestamp rather than a Date. Since Timestamp is a subclass of Date this generally isn't a problem. Where you might notice a difference is if you relied on the conversion from DATE to Date to truncate the time component or if you do toString on the value. Otherwise the change should be transparent.
If for some reason your app is very sensitive to this change and you simply must have the 9i-10g behavior, there is a connection property you can set. Set mapDateToTimestamp to false and the driver will revert to the default 9i-10g behavior and map DATE to Date.
構成:
<property name="hibernate.connection.oracle.jdbc.V8Compatible">true</property>
またはデータベース#データベース#
dateをtimestampタイプに設定します.
各ドライバパッケージに存在するBUG:
参照
Driver Result
with classes12.zip at C:\Oracle\Ora81\jdbc\lib, Oracle JDBC Drivers release 8.1.6 OK, no problem found
with "oracle 8.1.7 driver\classes12.zip", oracle 8.1.7 driver OK, no problem found
with "oracle 10i\classes12.jar", oracle 10i driver ID corrputed. Bug
with "oracle9i driver\classes12.jar", oracle 9i driver ID corrputed. Bug
with "oracle 10i\ojdbc14.jar", oracle 10i driver ID corrputed. Bug
with "oracle9i driver\ojdbc14.jar", oracle 9i driver ID corrputed. Bug