-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Warning with Hibernate and SQL Server
PostPosted: Fri Nov 17, 2006 4:57 am 
Newbie

Joined: Thu Feb 16, 2006 1:27 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 6:26 pm 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
Naxe,

First, sorry. I think you e-mailed me about this and I dropped it.

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...

Code:
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:

Code:
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 10:55 am 
Newbie

Joined: Wed Apr 25, 2007 5:14 pm
Posts: 5
This reply was very helpful for me. I had a similar problem with DB2 warnings. Every time the pool acquired connection, the warnings were logged which cluttered my log files with redundant stack traces. I used a modified version of your listener to filter and log once:
Code:
    public void onAcquire(Connection c, String pdsIdt) throws SQLException
    {
        SQLWarning warning = c.getWarnings();
       
        // for all warnings
        while (warning != null)
        {
            if (warning.getMessage().contains("Extra connection property is ignored"))
            {
                if (!loggedPropertyWarning)
                {
                    // log once, no stack trace
                    log.warn(warning);
                    loggedPropertyWarning = true;
                }
            }
            else
            {
                // some other warning, log it with stack trace
                log.warn("connection pool warning", warning);
            }
           
            // next
            warning = warning.getNextWarning();
        }
       
        // prevent connection pool from logging
        c.clearWarnings();
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.