0

我正在尝试在 JSF/Primefaces 项目中使用 JPA + Hibernate 4.5.1。我正在使用 c3p0 进行连接池。启动应用程序时,c3p0 尝试初始化池,但身份验证失败。

这是我的persistence.xml:

    <persistence-unit name="ba">

    <properties>
        <property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://x.x.x.x:1433/ba"/>
        <property name="hibernate.connection.username" value="ba"/>
        <property name="hibernate.connection.password" value="ENC(UcsChwXw5vYnM7w2S9XUaw==)" />            
        <property name="hibernate.connection.provider_class" value="org.jasypt.hibernate4.connectionprovider.EncryptedPasswordC3P0ConnectionProvider"/>
        <property name="hibernate.connection.encryptor_registered_name" value="configurationHibernateEncryptor"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>  
        <property name="hibernate.connection.release_mode" value="on_close"/>
        <property name="hibernate.archive.autodetection" value="class, hbm"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.c3p0.validate" value="true"/>
        <property name="hibernate.c3p0.min_size" value="5"/>
        <property name="hibernate.c3p0.max_size" value="20"/>
        <property name="hibernate.c3p0.timeout" value="8"/>
        <property name="hibernate.c3p0.max_statements" value="50"/>
        <property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1;"/>
        <property name="hibernate.c3p0.idle_test_period" value="5"/>  
        <property name="hibernate.c3p0.idle_test_period" value="1200"/>
        <property name="hibernate.c3p0.acquire_increment" value="1"/>
    </properties>

</persistence-unit>

我在 ServletContextListener 中添加了以下内容:

  @Override
  public void contextInitialized(ServletContextEvent contextEvent) {
    StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
    strongEncryptor.setAlgorithm("PBEWithMD5AndDES");
    strongEncryptor.setPassword("password");      
    HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
    registry.registerPBEStringEncryptor("configurationHibernateEncryptor", strongEncryptor);

}

这些是“错误”行:

INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@b0d5e69
d [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSou
rce@b495f632 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDe
lay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterA
cquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> n
ull, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTest
er, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null,
 forceIgnoreUnresolvedTransactions -> false, identityToken -> 2rxe6q8s1103xfe10g
g38n|1712f3d, idleConnectionTestPeriod -> 1200, initialPoolSize -> 3, maxAdminis
trativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 8, maxIdleTimeExcess
Connections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnec
tion -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManag
erDataSource@b80b5127 [ description -> null, driverClass -> null, factoryClassLo
cation -> null, identityToken -> 2rxe6q8s1103xfe10gg38n|bc294a, jdbcUrl -> jdbc:
jtds:sybase://x.x.x.x:yyyy/crystal, properties -> {encryptor_registered_name=
configurationHibernateEncryptor, user=******, password=******, autocommit=true,
release_mode=auto} ], preferredTestQuery -> null, propertyCycle -> 0, statementC
acheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnecti
onOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflecti
veProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLoc
ation -> null, identityToken -> 2rxe6q8s1103xfe10gg38n|1976f39, numHelperThreads
 -> 3 ]


Jan 29, 2013 11:16:25 AM com.mchange.v2.resourcepool.BasicResourcePool$Scattered
AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@1de3
1b1 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to
acquire a needed new resource, we failed to succeed more than the maximum number
 of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Login failed for user 'xxxxx'.
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.j
ava:372)
        at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
        at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:603)
        at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java
:352)
        at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java
:50)
        at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
erDataSource.java:134)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:183)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:172)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
Pool.java:1074)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPe
ndingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
ePool.java:32)
        at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.ru
n(BasicResourcePool.java:1796)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:635)

Jan 29, 2013 11:16:25 AM com.mchange.v2.resourcepool.BasicResourcePool forceKill
Acquires
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicR
esourcePool@13dcf53 is interrupting all Threads waiting on a resource to check o
ut. Will try again in response to new client requests.
Jan 29, 2013 11:16:25 AM com.mchange.v2.resourcepool.BasicResourcePool forceKill
Acquires
WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicR
esourcePool@13dcf53 is interrupting all Threads waiting on a resource to check o
ut. Will try again in response to new client requests.   
4

1 回答 1

0

这是一个错误。请点击这里了解更多详情: http: //sourceforge.net/tracker/ ?func=detail&aid=3515794&group_id=183612&atid=905944

为了修复它,必须根据链接中提供的详细信息修改 Jasypt-hibernate4 提供的文件之一 (EncryptedPasswordC3P0ConnectionProvider)。

于 2013-01-29T11:33:43.740 回答