Sweet!  Thanks!


BR
Stefan





14 jan 2010 kl. 06.46 skrev Clinton Begin:

It wouldn't be hard to change that, but first, the best thing might be to just write your own transaction manager that works... it's pretty easy.

You can pass any class name in place of "MANAGED" in your configuration.

For example, here's the Managed connection implementation...

public class ManagedTransactionFactory implements TransactionFactory {
  public void setProperties(Properties props) {
  }
public Transaction newTransaction(Connection conn, boolean autoCommit) {
    return new ManagedTransaction(conn);
  }
}

public class ManagedTransaction implements Transaction {
  private Connection connection;
  public ManagedTransaction(Connection connection) {
    this.connection = connection;
  }
  public Connection getConnection() {
    return connection;
  }
  public void commit() throws SQLException {
    // Does nothing
  }
  public void rollback() throws SQLException {
    // Does nothing
  }
  public void close() throws SQLException {
    // Does nothing
  }
}


On Wed, Jan 13, 2010 at 10:28 PM, Stefan Hagström <stha...@gmail.com> wrote:
Hi, thanks!

Its a managed connection (CMT).
When using plain JBDC in an SLSB the jdbc connection is opened and closed in each method. When closing a method it is not really closed but rather returned to the connection pool.

The container is afaik responsible for commit/rollback of the current transaction, not closing the "checked out"
connection.

Does this make sense? does anyone else got ibatis working with jboss 5.1?


BR
Stefan


2010/1/14 Clinton Begin <clinton.be...@gmail.com>

If it's a managed connection, it will not be closed, even if you call session.close(). The underlying container / transaction manager is responsible for closing it. So the transaction scope for your SLSB should be opening and closing the connection. Otherwise, change the transaction type to JDBC.

Clinton


On Wed, Jan 13, 2010 at 2:43 PM, Stefan Hagström <ste...@iserv.se> wrote:




Hi!

I'm new to Ibatis, and have tried to create a simple slsb as a dao with ibatis 3 with jboss 5.

However it seems like connection are not closed/returned. Jboss is complaining about connections not beeing closed:

21:32:15,146 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk5.wrappedconnectionj...@8cffca
java.lang.Throwable: STACKTRACE

I've attached the configuration and slsb, any ideas?


<configuration>
<settings>
<setting name="cacheEnabled" value="false"/>
<setting name="lazyLoadingEnabled" value="false"/>
</settings>
  <typeAliases>
    <typeAlias type="dto.valuecode.ValueCode" alias="ValueCode"/>
  </typeAliases>

  <environments default="prod">

       <environment id="prod">
       <transactionManager type="MANAGED">
       </transactionManager>
       <dataSource type="JNDI">
         <property name="data_source" value="java:/kalenderDB"/>
       </dataSource>
     </environment>
  </environments>


  <mappers>
    <mapper resource="META-INF/ValueCode.xml"/>
  </mappers>
</configuration>



@Stateless
public class ValueCodeDao implements ValueCodeDaoInterface {

SqlSessionFactory sqlSessionFactory=null;

@PostConstruct
public void setup(){

System.out.println("Reading Ibatis configuration for ValueCodeDao");

String resource = "META-INF/ibatis.xml";
Reader reader;
try {
reader = Resources .getResourceAsReader(this.getClass().getClassLoader(),resource);
sqlSessionFactory =  new SqlSessionFactoryBuilder().build(reader);


} catch (IOException e) {

e.printStackTrace();
}

}


public int getNextValueCodeNumber(){

SqlSession session = sqlSessionFactory.openSession();
session.close();

return 1;

}


}





Reply via email to