问题
I'm using Sybase ASE with Hibernate-core 4.2.8.Final, hiberante-c3po 4.2.8.Final, hibernate-search 4.4.2.Final
My hibernate.cfg.xml file looks like so
<property name="hibernate.connection.driver_class">com.sybase.jdbc4.jdbc.SybDataSource</property>
<property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
<property name="hibernate.connection.url">jdbc:sybase:Tds:server:5000/dev</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.idle_test_period">1800</property>
<property name="hibernate.c3p0.timeout">3600</property>
When I add in hibernate.c3p0 I get the following SQLWarning, but when I remove it, the exception goes away. Does anybody know how to get rid of the warning or where the defaultdb is coming from?
c3p0.SQLWarnings Server user id 29 is not a valid user in database 'defaultdb'
java.sql.SQLWarning: Server user id 29 is not a valid user in database 'defaultdb'
at com.sybase.jdbc4.jdbc.SybConnection.convertToWarnings(SybConnection.java:2893)
at com.sybase.jdbc4.jdbc.SybConnection.chainWarnings(SybConnection.java:2909)
at com.sybase.jdbc4.tds.Tds.processLoginAckToken(Tds.java:5125)
at com.sybase.jdbc4.tds.Tds.doLogin(Tds.java:724)
at com.sybase.jdbc4.tds.Tds.login(Tds.java:578)
at com.sybase.jdbc4.jdbc.SybConnection.tryLogin(SybConnection.java:415)
at com.sybase.jdbc4.jdbc.SybConnection.handleHAFailover(SybConnection.java:3226)
at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:341)
at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:248)
at com.sybase.jdbc4.jdbc.SybDriver.connect(SybDriver.java:233)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
c3p0.SQLWarnings Cannot open default database 'defaultdb'.
回答1:
You are almost certainly experiencing the warning regardless of whether you use c3p0, but c3p0 is very fussy about periodically checking Connections for warnings and logging them.
SQLWarnings
are Exception objects that are typically never thrown. They are chained into a linked list and associated with Connection
objects. On any Connection
, you can check for warnings by calling myConnection.getWarnings()
and clear warnings by calling myConnection.clearWarnings()
.
In practice, very few applications bother to check for and clear warnings, but c3p0 does, so if your application is generating warnings for some reason, you'll see them when you turn c3p0 on, but they'll seem to disappear without it.
If this is annoying and you want to ignore warnings, just turn off logging for logger com.mchange.v2.c3p0.SQLWarnings
in whatever logging library you use.
If you want to understand these warnings rather than just ignore them, well, you've have to wait for someone who knows Sybase better than I do to respond.
回答2:
I have no clue about the hibernate section, but the error is due to wrong configuration of your Sybase user. You will need admin sql access to fix this. The user (suser_name(29)) is not yet added to the 'defaultdb' (database name) which the application is trying to connect to.
with an admin login you should execute,
sp_modifylogin suser_name(29), defdb, "defaultdb"
go
Another chance is that, the user name is not yet added to the database "defaultdb", in this case as admin,
use "defaultdb"
go
sp_adduser user_name or suser_name(29)
go
来源:https://stackoverflow.com/questions/21731927/c3p0-sqlwarnings-server-user-id-29-is-not-a-valid-user-in-database-defaultdb