#30 Warning with Hibernate and SQL Server

closed
nobody
None
5
2007-01-05
2006-11-17
Anonymous
No

My apologies for my english.

I'm using C3P0 with Hibernate and SQL Server 2000 on TOMCAT 5.5. I ever have the following warnings when the server start or a SQL request is processed :

09:27:08,109 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
09:27:08,109 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to W4TI
09:27:08,109 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
09:27:08,109 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Le contexte de la base de données a été changé en 'W4TI'.
09:27:08,109 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState:
09:27:08,109 WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english

However, the database passed in the URL connection is the good one (W4TI). The defaults schema and catalog are set.

If I use another pool (for instance DBCP), this warnings disappear....

What does it mean?
How to solve it with C3P0?

Regards.

Discussion

  • Nobody/Anonymous

    Logs tomcat

     
  • Steve Waldman

    Steve Waldman - 2006-11-20

    Logged In: YES
    user_id=175530
    Originator: NO

    Naxe,

    First, sorry for the delayed reponse.

    Looking around, it looks like SQL Server sometimes sets these warnings on Connections it issues. If so, and if Hibernate reports warnings set on Connections, then you'll see them until somebody calls clearWarnings() on your Connections.

    c3p0 should really be managing the SQLWarnings, as part of Connection state. It looks like it doesn't, though. It will before its next minor release! :) Sorry!

    For now, the easiest way to resolve this would be to get SQLServer to stop setting these warnings on Connections. If you can't do that, you can write a c3p0 ConnectionCustomizer, like so...

    package com.zaxe.foo;

    import com.mchange.v2.c3p0.*;
    import java.sql.*;

    public class ClearWarningsConnectionCustomizer
    extends AbstractConnectionCustomizer
    {
    public void onAcquire( Connection c, String pdsIdt )
    {
    SQLWarning warning = c.getWarnings();
    while (warning != null)
    {
    logWarning(warning);
    warning = warning.getNextWarning();
    }
    c.clearWarnings();
    }

    private void logWarning(SQLWarning w)
    { /* log at DEBUG level */ }
    }

    This will only work in c3p0-0.9.1-preX [use c3p0-0.9.1-pre11]. Once you've defined the class, use the c3p0 config param c3p0.connectionCustomizerClassName to get c3p0 to instantiate the class and attach it to your DataSource. [See the docs to c3p0-0.9.1-pre11.]

    If you don't know where to log the warnings, here's the same example modified to use c3p0's built-in logging library:

    package com.zaxe.foo;

    import com.mchange.v2.c3p0.*;
    import com.mchange.v2.log.*;
    import java.sql.*;

    public class ClearWarningsConnectionCustomizer
    extends AbstractConnectionCustomizer
    {
    private final static MLogger logger = MLog.getLogger( ClearWarningsConnectionCustomizer.class );

    public void onAcquire( Connection c, String pdsIdt )
    {
    SQLWarning warning = c.getWarnings();
    while (warning != null)
    {
    logWarning(warning);
    warning = warning.getNextWarning();
    }
    c.clearWarnings();
    }

    private void logWarning(SQLWarning w)
    { logger.log(MLevel.FINE, "Warning set on Connection: " + w, w); }
    }

    Hope this helps! Good luck!

    Steve

     
  • Steve Waldman

    Steve Waldman - 2007-01-05

    Logged In: YES
    user_id=175530
    Originator: NO

    Okay. I think this is fixed as of c3p0-0.9.1-pre12. I'm closing the issue, but do resurrect it if you find that it isn't solved.

     
  • Steve Waldman

    Steve Waldman - 2007-01-05
    • status: open --> closed
     

Log in to post a comment.