-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using Hibernate with Informix, without transactions
PostPosted: Wed Sep 21, 2005 12:17 pm 
Newbie

Joined: Wed Sep 21, 2005 12:09 pm
Posts: 5
My problem is of using Hibernate with an Informix database that is set to no-log. With this setting, Informix databases do not support transactions.

I am working on a stand-alone application, not in a managed env.

Is this possible? How?

Below are the details:

Hibernate version: 3.1

Name and version of the database you are using: Informix 9.4

Full stack trace of any exception that occurs:

org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.tsoft.metadata.repository.TsDBReposiroryContainer.byPattern(TsDBReposiroryContainer.java:35)
at com.tsoft.manageTools.schema.SchemaUtils.backupRepositoryToFileRepository(SchemaUtils.java:319)
at com.tsoft.manageTools.schema.SchemaUtils.main(SchemaUtils.java:184)


java.sql.SQLException: Transactions not supported
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
at com.informix.jdbc.IfxSqliConnect.setAutoCommit(IfxSqliConnect.java:1812)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:112)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at com.tsoft.metadata.repository.TsDBRepository.<init>(TsDBRepository.java:81)
at com.tsoft.manageTools.schema.SchemaUtils.main(SchemaUtils.java:174)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 5:29 pm 
Newbie

Joined: Wed Sep 21, 2005 5:17 pm
Posts: 1
I've gotten Hibernate working(for testing) not using Transactions.

What I did was create a class that extends org.hibernate.Transaction

that had a pointer to the JDBC context(passed on the constructor)

The begin() method just set auto commit=true

Look at the org.hibernate.transaction.JDBCTransaction class as a starting point (You want a version that always sets auto-commit to false)

You'll also have to tell Hibernate to use your new class (by setting transaction.factory_class to a factory class that creates instances of the new Transaction class you create)

I'd think twice about running without transactions. If a database exception happens you won't know which entites got written to the database and which ones didn't. I think the Hibernate team recommends against using Hibernate this way.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 3:43 am 
Newbie

Joined: Wed Sep 21, 2005 12:09 pm
Posts: 5
My problem seems to happen even before Hibernate tries to open a transaction. When it opens a connection, Hibernate runs the following code:

Code:
      log.debug("opening new JDBC connection");
      Connection conn = DriverManager.getConnection(url, connectionProps);
      if (isolation!=null) conn.setTransactionIsolation( isolation.intValue() );
      if ( conn.getAutoCommit() ) conn.setAutoCommit(false);


the connection
Code:
conn.getAutoCommit()
returns true, but when tring
Code:
conn.setAutoCommit(false)
I get an exception (the one in the first post).

Any idea how to open a connection with autoCommit == false?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 4:57 am 
Newbie

Joined: Wed Sep 21, 2005 12:09 pm
Posts: 5
I have found the solution :)
I had to register a new ConnectionProvider, that is a copy of the original hibernate class DriverManagerConnectionProvider, but with commenting the two lines where setting autoCommit(false).

This allows me to read (not write ) data from a database without transactions using hibernate.

Yoav.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.