今天配置hibernate4。发现报
17:55:06,815 INFO AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge16q9a8u2d4lyv35wl|5a6efc31, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge16q9a8u2d4lyv35wl|5a6efc31, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@192.168.1.229:1521:WDRPT, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 5, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] 17:55:07,741 WARN TypeInfo:126 - HHH000273: Error accessing type info result set : java.sql.SQLException: 数字溢出
数字溢出。搜了一下。都说映射文件错误了。我把全部配置的映射文件都去掉,还是报错,跟代码一下,是c3p0的获取meta的问题
public static LinkedHashSet<TypeInfo> extractTypeInfo(DatabaseMetaData metaData) { final LinkedHashSet<TypeInfo> typeInfoSet = new LinkedHashSet<TypeInfo>(); try { final ResultSet resultSet = metaData.getTypeInfo(); try { while ( resultSet.next() ) { typeInfoSet.add( new TypeInfo( resultSet.getString( "TYPE_NAME" ), resultSet.getInt( "DATA_TYPE" ), interpretCreateParams( resultSet.getString( "CREATE_PARAMS" ) ), resultSet.getBoolean( "UNSIGNED_ATTRIBUTE" ), resultSet.getInt( "PRECISION" ),//commend by danielinbiti,blob字段时,这个数字超出了int的范围。用long是可以获取的 resultSet.getShort( "MINIMUM_SCALE" ), resultSet.getShort( "MAXIMUM_SCALE" ), resultSet.getBoolean( "FIXED_PREC_SCALE" ), resultSet.getString( "LITERAL_PREFIX" ), resultSet.getString( "LITERAL_SUFFIX" ), resultSet.getBoolean( "CASE_SENSITIVE" ), TypeSearchability.interpret( resultSet.getShort( "SEARCHABLE" ) ), TypeNullability.interpret( resultSet.getShort( "NULLABLE" ) ) ) ); } } catch ( SQLException e ) { LOG.unableToAccessTypeInfoResultSet( resultSet.getString( "TYPE_NAME" )+","+resultSet.getInt( "DATA_TYPE" ) ); LOG.unableToAccessTypeInfoResultSet( e.toString() ); } finally { try { resultSet.close(); } catch ( SQLException e ) { LOG.unableToReleaseTypeInfoResultSet(); } } } catch ( SQLException e ) { LOG.unableToRetrieveTypeInfoResultSet( e.toString() ); } return typeInfoSet; }于是,改动了一下该类
public static LinkedHashSet<TypeInfo> extractTypeInfo(DatabaseMetaData metaData) { final LinkedHashSet<TypeInfo> typeInfoSet = new LinkedHashSet<TypeInfo>(); try { final ResultSet resultSet = metaData.getTypeInfo(); try { while ( resultSet.next() ) { long precision = resultSet.getLong( "PRECISION" );//add by danielinbiti int int_p = precision>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)precision;//add by danielinbiti,这么改动反正基于眼下该方法的逻辑是没问题的。 typeInfoSet.add( new TypeInfo( resultSet.getString( "TYPE_NAME" ), resultSet.getInt( "DATA_TYPE" ), interpretCreateParams( resultSet.getString( "CREATE_PARAMS" ) ), resultSet.getBoolean( "UNSIGNED_ATTRIBUTE" ), int_p, resultSet.getShort( "MINIMUM_SCALE" ), resultSet.getShort( "MAXIMUM_SCALE" ), resultSet.getBoolean( "FIXED_PREC_SCALE" ), resultSet.getString( "LITERAL_PREFIX" ), resultSet.getString( "LITERAL_SUFFIX" ), resultSet.getBoolean( "CASE_SENSITIVE" ), TypeSearchability.interpret( resultSet.getShort( "SEARCHABLE" ) ), TypeNullability.interpret( resultSet.getShort( "NULLABLE" ) ) ) ); } } catch ( SQLException e ) { LOG.unableToAccessTypeInfoResultSet( e.toString() ); } finally { try { resultSet.close(); } catch ( SQLException e ) { LOG.unableToReleaseTypeInfoResultSet(); } } } catch ( SQLException e ) { LOG.unableToRetrieveTypeInfoResultSet( e.toString() ); } return typeInfoSet; }