Hibernate and Informix
Posted in 2008
A user on IDS 9.4 with Hibernate 3.0 and the Informix JDBC driver saw SQLState 01I01 "Database has transactions" warnings and found inserts were only saved if he explicitly called commit on the connection. Replies explained the 01I01/01I04 messages are harmless informational warnings the Informix driver returns after connect (telling the app whether the database is logged), not errors. The real cause was that Hibernate turns autocommit off, so the application must manage transactions itself (begin/commit) or enable autocommit; a pointer to hibernate.org/403.html resolved it, and the poster confirmed it worked.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Connectivity: ODBC / JDBC / .NET, Security, Permissions & Auditing, Java & JDBC Development, Internationalization & Character Sets, Versions, Editions & End-of-Life
Hi, I'm having an issue with IDS 9.4, hibernate v3.0 and JDBC v3 To insert a record I have to preform a commit. The engine was complaining of a warning: SQLState: 01I01 which says the Database has transactions. Which I'm not sure what that means. I'm not sure if the issue is with the Java code or the hibernate config file. I did find info about the SQLState message but that was for older versions of hibernate so I assume by v3 they had fixed those issues. Does anyone have any ideas? Thanks public class FirstExample { public static void main(String[] args) { Session session = null; try{ // This step will read hibernate.cfg.xml and prepare hibernate for use SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); //session.beginTransaction(); //Create new instance of Contact and set values in it by reading them from form object System.out.println("Inserting Record"); Contact contact = new Contact(); contact.setId(0); contact.setFirstName("Bill"); contact.setLastName("Smith"); contact.setEmail("Bill.smith@reece.com"); session.save(contact); session.connection().commit(); }catch(Exception e){ System.out.println(e.getMessage()); }finally{ // Actual contact insertion will happen at this step System.out.println("Done"); session.flush(); session.close(); } } } <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.informix.jdbc.IfxDriver</property> <property name="hibernate.connection.url">jdbc:informix-sqli://d0101:8933/uat3:INFORMIXSER VER=reeceuat3</property> <property name="hibernate.connection.username">bea</property> <property name="hibernate.connection.password">bea</property> <property name="hibernate.connection.pool_size">10</property> <property name="show_sql">true</property> <property name="dialect">org.hibernate.dialect.InformixDialect</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory </property> <!-- Mapping files --> <mapping resource="contact.hbm.xml"/> </session-factory> </hibernate-configuration>
As you might know you can create informix databases with or without transaction log. So after connecting to the database there are two warnings on this connection object and hibernate writes them out. That's what you and I and all others see: WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] SQL Warning: 0, SQLState: 01I01 WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] Database has transactions WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] SQL Warning: 0, SQLState: 01I04 WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] Database selected It's not a problem of hibernate, it's a problem of the informix JDBC drivers. For professional software and systems I would expect that the database used has transactions and would not see this as a warning. And connecting to the database is what I want and defined this the connection URL. So this is no warning for me either. Using the small program beneath you'll get the warnings too and there seems to be no way to get rid of them. package informix; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLWarning; import com.informix.jdbc.IfxDriver; public final class Test { public static void main( String[] args ) { String hostname = "XXX"; try { Class.forName( "com.informix.jdbc.IfxDriver" ); String connectionUrl = "jdbc:informix-sqli://" + hostname + ":11100/xxx_lafr:INFORMIXSERVER=XXX"; Driver driver = DriverManager.getDriver( connectionUrl ); System.out.println( "Connecting to " + connectionUrl ); Connection con = DriverManager.getConnection( connectionUrl, "xxx", "***" ); if ( con != null ) { System.out.println( "Connected to server!" ); SQLWarning warning = con.getWarnings(); if ( warning == null ) { System.out.println( "No warnings!"); } else { System.out.println( "Warnings:"); while ( warning != null ) { System.out.println( "ErrorCode: " + warning.getErrorCode() ); System.out.println( "SQLState: " + warning.getSQLState() ); System.out.println( warning.getMessage() ); warning = warning.getNextWarning(); } } } } catch ( Exception e ) { e.printStackTrace(); } } } DAVID PLEYDELL wrote: > Hi, > > I'm having an issue with IDS 9.4, hibernate v3.0 and JDBC v3 > To insert a record I have to preform a commit. The engine was complaining of a > warning: SQLState: 01I01 which says the Database has transactions. Which I'm > not sure what that means. > > I'm not sure if the issue is with the Java code or the hibernate config file. > I did find info about the SQLState message but that was for older versions of > hibernate so I assume by v3 they had fixed those issues. Does anyone have any > ideas? Thanks > > public class FirstExample { > > public static void main(String[] args) { > > Session session = null; > > try{ > > // This step will read hibernate.cfg.xml and prepare hibernate for use > > SessionFactory sessionFactory = new > Configuration().configure().buildSessionFactory(); > > session =sessionFactory.openSession(); > > //session.beginTransaction(); > > //Create new instance of Contact and set values in it by reading them from > form object > > System.out.println("Inserting Record"); > > Contact contact = new Contact(); > > contact.setId(0); > > contact.setFirstName("Bill"); > > contact.setLastName("Smith"); > > contact.setEmail("Bill.smith@reece.com"); > > session.save(contact); > > session.connection().commit(); > > }catch(Exception e){ > > System.out.println(e.getMessage()); > > }finally{ > > // Actual contact insertion will happen at this step > > System.out.println("Done"); > > session.flush(); > > session.close(); > > } > > } > } > > <?xml version='1.0' encoding='utf-8'?> > <!DOCTYPE hibernate-configuration PUBLIC > "-//Hibernate/Hibernate Configuration DTD//EN" > "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> > > <hibernate-configuration> > <session-factory> > > <property > name="hibernate.connection.driver_class">com.informix.jdbc.IfxDriver</property> > > <property > name="hibernate.connection.url">jdbc:informix-sqli://d0101:8933/uat3:INFORMIXSER VER=reeceuat3</property> > > <property name="hibernate.connection.username">bea</property> > > <property name="hibernate.connection.password">bea</property> > > <property name="hibernate.connection.pool_size">10</property> > > <property name="show_sql">true</property> > > <property name="dialect">org.hibernate.dialect.InformixDialect</property> > > <property name="hibernate.hbm2ddl.auto">update</property> > > <property > name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory </property> > > <!-- Mapping files --> > > <mapping resource="contact.hbm.xml"/> > </session-factory> > </hibernate-configuration> > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > See you at the IIUG Informix 2008 Conference > The Power Conference for Informix Professionals > April 27 - 30, 2008 Marriott Overland Park (Kansas City), Kansas > http://www.iiug.org/conf > Registration Now Open!! > >
Hi, This is really no hibernate problem, but instead a "feature" of informix. It defines the sqlwarn structure (not only in JDBC) to pass back information about the state of the last command to the calling program. After connect, the information includes (beneath other info) if the database is transactional or not. Based on this information, the application can decide to continue working or throw an error (e.g. if transactions are not supported, but the application needs to have transactions). The statement did run well and there is not need to care about this "warning". Marcus -----Original Message----- From: Frank Langelage [mailto:frank@lafr.de] Sent: Thursday, May 01, 2008 6:26 PM To: ids@iiug.org Subject: Re: Hibernate and Informix [11946] As you might know you can create informix databases with or without transaction log. So after connecting to the database there are two warnings on this connection object and hibernate writes them out. That's what you and I and all others see: WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] SQL Warning: 0, SQLState: 01I01 WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] Database has transactions WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] SQL Warning: 0, SQLState: 01I04 WARN [org.hibernate.util.JDBCExceptionReporter#logWarnings] Database selected It's not a problem of hibernate, it's a problem of the informix JDBC drivers. For professional software and systems I would expect that the database used has transactions and would not see this as a warning. And connecting to the database is what I want and defined this the connection URL. So this is no warning for me either. Using the small program beneath you'll get the warnings too and there seems to be no way to get rid of them. package informix; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLWarning; import com.informix.jdbc.IfxDriver; public final class Test { public static void main( String[] args ) { String hostname = "XXX"; try { Class.forName( "com.informix.jdbc.IfxDriver" ); String connectionUrl = "jdbc:informix-sqli://" + hostname + ":11100/xxx_lafr:INFORMIXSERVER=XXX"; Driver driver = DriverManager.getDriver( connectionUrl ); System.out.println( "Connecting to " + connectionUrl ); Connection con = DriverManager.getConnection( connectionUrl, "xxx", "***" ); if ( con != null ) { System.out.println( "Connected to server!" ); SQLWarning warning = con.getWarnings(); if ( warning == null ) { System.out.println( "No warnings!"); } else { System.out.println( "Warnings:"); while ( warning != null ) { System.out.println( "ErrorCode: " + warning.getErrorCode() ); System.out.println( "SQLState: " + warning.getSQLState() ); System.out.println( warning.getMessage() ); warning = warning.getNextWarning(); } } } } catch ( Exception e ) { e.printStackTrace(); } } } DAVID PLEYDELL wrote: > Hi, > > I'm having an issue with IDS 9.4, hibernate v3.0 and JDBC v3 To insert > a record I have to preform a commit. The engine was complaining of a > warning: SQLState: 01I01 which says the Database has transactions. > Which I'm not sure what that means. > > I'm not sure if the issue is with the Java code or the hibernate > config file. > I did find info about the SQLState message but that was for older > versions of > hibernate so I assume by v3 they had fixed those issues. Does anyone > have any > ideas? Thanks > > public class FirstExample { > > public static void main(String[] args) { > > Session session = null; > > try{ > > // This step will read hibernate.cfg.xml and prepare hibernate for use > > SessionFactory sessionFactory = new > Configuration().configure().buildSessionFactory(); > > session =sessionFactory.openSession(); > > //session.beginTransaction(); > > //Create new instance of Contact and set values in it by reading them > from form object > > System.out.println("Inserting Record"); > > Contact contact = new Contact(); > > contact.setId(0); > > contact.setFirstName("Bill"); > > contact.setLastName("Smith"); > > contact.setEmail("Bill.smith@reece.com"); > > session.save(contact); > > session.connection().commit(); > > }catch(Exception e){ > > System.out.println(e.getMessage()); > > }finally{ > > // Actual contact insertion will happen at this step > > System.out.println("Done"); > > session.flush(); > > session.close(); > > } > > } > } > > <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE > hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration > DTD//EN" > "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> > > <hibernate-configuration> > <session-factory> > > <property > name="hibernate.connection.driver_class">com.informix.jdbc.IfxDriver</pr operty> > > <property > name="hibernate.connection.url">jdbc:informix-sqli://d0101:8933/uat3:INF ORMIXSERVER=reeceuat3</property> > > <property name="hibernate.connection.username">bea</property> > > <property name="hibernate.connection.password">bea</property> > > <property name="hibernate.connection.pool_size">10</property> > > <property name="show_sql">true</property> > > <property > name="dialect">org.hibernate.dialect.InformixDialect</property> > > <property name="hibernate.hbm2ddl.auto">update</property> > > <property > name="transaction.factory_class">org.hibernate.transaction.JTATransactio nFactory</property> > > <!-- Mapping files --> > > <mapping resource="contact.hbm.xml"/> </session-factory> > </hibernate-configuration> > > > ************************************************************************ ******* > Forum Note: Use "Reply" to post a response in the discussion forum. > > See you at the IIUG Informix 2008 Conference The Power Conference for > Informix Professionals April 27 - 30, 2008 Marriott Overland Park > (Kansas City), Kansas http://www.iiug.org/conf Registration Now Open!! > > ************************************************************************ ******* Forum Note: Use "Reply" to post a response in the discussion forum. See you at the IIUG Informix 2008 Conference The Power Conference for Informix Professionals April 27 - 30, 2008 Marriott Overland Park (Kansas City), Kansas http://www.iiug.org/conf Registration Now Open!!
Thanks for all the replies. The issue is that the insert doesn't happen. The message is only a warning and hibernate completes ok. However without using the commit command it won't actually insert the data into the table. In the example there is no transaction setup on purpose that I can see. So the question is: 1. Is the hibernate config incorrect? ie is there something that implies a transaction when it wasn't meant to be? 2. Is there setting on the database that implies a transactions? (I wouldn't think so as I've setup apps using straight JDBC calls as per the example posted before and never had any issues inserting data into the tables. Only since trying to use hibernate instead has this warning occurred which I would ignore IF data was being inserted into the table.) David
Hi, Not really sure about that, but I believe Hibernate is setting autocommit to false. So you have to keep track of commit/rollback yourself. Maybe setting autoCommit to true will help in case you do not want to do an explicit transaction. (you should e.g. try to print out the autoCommit value as a test) Marcus -----Original Message----- From: DAVID PLEYDELL [mailto:david.pleydell@reece.com.au] Sent: Thursday, May 01, 2008 11:56 PM To: ids@iiug.org Subject: Re: RE: Re: Hibernate and Informix [11949] Thanks for all the replies. The issue is that the insert doesn't happen. The message is only a warning and hibernate completes ok. However without using the commit command it won't actually insert the data into the table. In the example there is no transaction setup on purpose that I can see. So the question is: 1. Is the hibernate config incorrect? ie is there something that implies a transaction when it wasn't meant to be? 2. Is there setting on the database that implies a transactions? (I wouldn't think so as I've setup apps using straight JDBC calls as per the example posted before and never had any issues inserting data into the tables. Only since trying to use hibernate instead has this warning occurred which I would ignore IF data was being inserted into the table.) David ************************************************************************ ******* Forum Note: Use "Reply" to post a response in the discussion forum. See you at the IIUG Informix 2008 Conference The Power Conference for Informix Professionals April 27 - 30, 2008 Marriott Overland Park (Kansas City), Kansas http://www.iiug.org/conf Registration Now Open!!
See http://www.hibernate.org/403.html for some explanations. Marcus Haarmann wrote: > Hi, > > Not really sure about that, but I believe Hibernate is setting > autocommit to false. > So you have to keep track of commit/rollback yourself. > Maybe setting autoCommit to true will help in case you do not want to do > an explicit transaction. (you should e.g. try to print out the > autoCommit value as a test) > > Marcus > >
Thanks. That works and explans why the tutorial example didn't work as per the code sample provided. David