HIBERNATE JBoss.org
 |  Register  | 
     
News 
About 
   Feature List 
   Road Map 
Documentation 
   Related Projects 
   External Documentation 
Download 
Forum & Mailinglists 
Support & Training 
JIRA Issue Tracking
Wiki Community Area


Hibernate Public Training Courses


Get Hibernate in Action eBook!


JavaWorld 2003 Finalist


Jolt Award 2004 Winner
      
Documentation > FAQs > Hibernate Users FAQ - Platform Specific

Hibernate Users FAQ - Platform Specific

Platform Specific Issues

Hibernate expects my JDBC driver to support JDBC2 but it doesn't!

Set

hibernate.jdbc.batch_size=0
hibernate.jdbc.use_scrollable_resultsets=false

or upgrade your driver to the latest version. Hibernate chooses sensible default values for these properties, based upon your SQL dialect.

My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?

Batch updates seem to be cause problems for some JDBC drivers that claim to support them. We found that batch updates should be disabled for DB2 and Sybase.

Why is Microsoft's own JDBC driver for SQL server not supported?

The Hibernate test suite does not complete successfully using Microsoft's driver (even though most of the individual tests are successful). It appears that the failures are due to some strange handling of dates (exactly the same problem occurs with the DataDirect Connect for JDBC driver, which appears to be the same driver). Some people are using Hibernate with the Microsoft driver but they do so at their own risk. Users of the Microsoft driver should not report problems without first verifying that the problem occurs with one of the recommended drivers. The standard test configuration is SQL Server 2000 + JSQL. An evaluation version of JSQL may be downloaded from

http://www.j-netdirect.com

Hibernate doesn't work with my MS SQL 2000 JDBC driver?

(Glen Stampoultzis)

If you're using Hibernate with the Microsoft SQL Server 2000 JDBC driver chances are you'll run into this problem:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]
Can't start a cloned connection while in manual transaction mode.

Simply add SelectMethod=Cursor; to your connection string. There's a MS knowledge base article with more information.

Are there known issues with Interbase / Firebird?

(Michael Jakl)

Yes. Due to some limitations in Interbase / Firebird we must use some workarounds:

Always set the size of your statement cache to zero (hibernate.statement_cache.size or hibernate.c3p0.max_statements)

If you are altering tables you should be in single user mode. This can be achieved by running gfix -shut. It's also sufficient to have only one database connection open (eg. immediately after starting the application). If more than one connection is open, you will see errors like "table is in use". To restart your database use gfix -online.

I'm having problems with WebLogic Server!

The JNDI implementation in WebLogic Server does not appear to support the Referenceable interface, and exhibits some rather strange behaviour when binding Serializable objects. Please direct complaints to BEA.

Workarounds include using a different JNDI implementation (eg. Sun's FSContext) or using some other means of obtaining a SessionFactory.

See also Mathias' Blog!

The forum users believe there's some problem if you do it the regular way like most app server. Therefore, try the following (which works for me). Use a WLS Startup class to bind Hibernate Session Factory object in WLS JNDI. Here's an excerpt of a possible code:

public class WLSStartup implements T3StartupDef
{
    public static final String SESSION_FACTORY_JNDI = "hibernate";
    public static final String URL = "t3://localhost:7001";

    /**
     * Called by WebLogic server upon startup. This is where everything should
     * be initialzed.
     *
     * @param   name        the JNDI name of this class
     * @param   args        any input parameters
     *
     * @return              the status.
     *
     * @throws  Exception   in case of any error
     */

    public String startup(  String name, Hashtable args ) throws Exception
    {
        String       METHOD_NAME        = "startup ";

        // Bind the various Hibernate Object to the Weblogic JNDI
        try
        {
            log ( METHOD_NAME + " Going to bind Hibernate object. " );
            doBind( );
            log ( METHOD_NAME + " Bound Hibernate object!" );
        }
        catch ( Exception exception )
        {
            log ( METHOD_NAME + " Exception while binding Hibernate Object to Weblogic JNDI" );
            exception.printStackTrace ( );
        }

        return "WLS Startup completed successfully";
    }

    /**
     * Performs Hibernate objects to Weblogic JNDI Namespace bindings.
     * It gets the initial context and binds the Hibernate objects to it.
     *
     * @param       None
     * @throws      Exception      in case of any errors
     */

    private static void doBind( ) throws Exception
    {
        Properties  environment  = null;
        InitialContext  context  = null;

        try
        {
            //Properties for storing JNDI configuration information
            environment = new Properties( );

            //Add initial context factory
            environment.put( Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
            environment.put( Context.PROVIDER_URL, URL );
            log( "Constructing an Initial Directory Context object" );
            context = new InitialContext( environment );            

            Datastore ds = Hibernate.createDatastore();
            SessionFactory factory = ds.buildSessionFactory();            

            if (factory == null)
                throw new Exception("SessionFactory cannot be built?!");
            
            try
            {
                if( context.lookup(SESSION_FACTORY_JNDI ) != null )
                    context.rebind(SESSION_FACTORY_JNDI, factory );
                else
                    context.bind(SESSION_FACTORY_JNDI, factory );
            }
            catch ( NamingException nameEx )
            {
                context.bind(SESSION_FACTORY_JNDI, factory );
            }            

        }
        catch ( NamingException nameExp )
        {
            throw new Exception( "NamingException: " + nameExp.getMessage( ));
        }
        catch( Exception excp )
        {
            throw excp;
        }
        finally
        {
            if( context != null )
            {
                try
                {
                    context.close( );
                    context = null;
                }
                catch ( NamingException nameExp )
                {
                    throw new Exception( "NamingException for context close: " nameExp.getMessage( ));
                }
            }
            environment = null;
        }

    }

Jar up the relevant Hibernate jar files and configure this Startup class under WLS console.

Then at your JNDI client (Servlet or EJBs for example) you can have a code similar to this excerpt below: -

Object objref;
Context context;
Hibernate.configure();

//The usual WLS JNDI context
context = getInitialContext(); 
objref = context.lookup(WLSStartup.SESSION_FACTORY_JNDI);
sessionFac = (SessionFactory) PortableRemoteObject.narrow(objref, SessionFactory.class);

if sessionFac == null)
       throw new Exception("Null SessionFactory found?!");

Works great with Struts 1.1 on WLS 6.X and 7.X. I've tested by writing some subclass relationship data into Oracle 8i!

Any questions can be directed to simon@see-consulting.com.

After a while, Oracle throws this exception: too many open cursors

The Oracle JDBC driver doesn't much like to have its prepared statements cached. Disable PreparedStatement caching for the connection pool.

MySQL throws an exception: Cannot disable AUTO_COMMIT

Download the latest MySQL driver.

I'm having trouble getting beta 3 to work under Resin. Dom4j complains that the XML parser can't validate.

The problem is that Resin's built-in parser does not resolve entities.

Christian Bauer:

I'm using Resin (2.1.6, 2.1.7) with Hibernate for all my Java projects, and it works just fine. My hibernate.jar is in the Context lib directory, though. The only thing I changed in Resin is the XML parser and XSLT processor:

<system-property javax.xml.transform.TransformerFactory=
        "org.apache.xalan.processor.TransformerFactoryImpl"/>
<system-property javax.xml.parsers.DocumentBuilderFactory=
        "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory=
        "org.apache.xerces.jaxp.SAXParserFactoryImpl"/>

Aapo Laakkonen:

And here is my Saxon settings:

<system-property javax.xml.transform.TransformerFactory=
        "com.icl.saxon.TransformerFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory=
        "com.icl.saxon.aelfred.SAXParserFactoryImpl"/>
<system-property javax.xml.parsers.DocumentBuilderFactory=
        "com.icl.saxon.om.DocumentBuilderFactoryImpl"/>

And you may replace them with whatever you like. In my case I just put saxon and xml-interfaces in resin/lib.

Tomcat throws java.lang.UnsupportedOperationException when fetching a JDBC connection

In Tomcat (maybe other situations) if you are using the built-in DBCP to as a JNDI datasource, be sure that you do not specify hibernate.connection.username or hibernate.connection.password in either hibernate.cfg.xml or hibernate.properties. DBCP does not implement the version of Datasource.getConnection() that takes a username and password.

      

coWiki