Hi,
I use the JBoss 4.0.1 EJB container with stateless session beans which call hibernate (3.0.x) to store the data.
I have a CMT trasaction that I use for hibernate CRUD operations. All operations work fine, but when the transaction ends at the session facade, the hibernate session is not committed.
AFAIK with CMT I dont have to commit the transaction myself, or close the connection. All these are done by the container.
If I use container managed entity beans, then all transactions are committed fine.
Does anybody know why my transactions are not committed when I use CMT with hibernate?
thanks, ALex.
Here is an output from the console, where we can see that the SQLCLI:SQLENDTRAN COMMIT is missing
Code:
11:19:37,578 INFO [STDOUT] Hibernate: insert into TX (ACCOUNT_ID, TIME_STAMP, AMOUNT, BALANCE, DESCRIPTION, TX_ID) values (?, ?, ?, ?, ?, ?)
11:19:37,578 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLPREPARE insert into TX (ACCOUNT_ID, TIME_STAMP, AMOUNT, BALANCE, DESCRIPTION, TX_ID) values (?, ?, ?, ?, ?, ?)
11:19:37,578 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLEXECUTE:48
11:19:37,588 INFO [STDOUT] Hibernate: insert into TX (ACCOUNT_ID, TIME_STAMP, AMOUNT, BALANCE, DESCRIPTION, TX_ID) values (?, ?, ?, ?, ?, ?)
11:19:37,588 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLEXECUTE:48
11:19:37,588 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLFREESTMT:48
11:19:37,588 INFO [STDOUT] Hibernate: update ACCOUNT set TYPE=?, DESCRIPTION=?, BALANCE=?, CREDIT_LINE=?, BEGIN_BALANCE=?, BEGIN_BALANCE_TIME_STAMP=? where ACCOUNT_ID=?
11:19:37,588 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLPREPARE update ACCOUNT set TYPE=?, DESCRIPTION=?, BALANCE=?, CREDIT_LINE=?, BEGIN_BALANCE=?, BEGIN_BALANCE_TIME_STAMP=? where ACCOUNT_ID=?
11:19:37,588 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLEXECUTE:49
11:19:37,598 INFO [STDOUT] Hibernate: update ACCOUNT set TYPE=?, DESCRIPTION=?, BALANCE=?, CREDIT_LINE=?, BEGIN_BALANCE=?, BEGIN_BALANCE_TIME_STAMP=? where ACCOUNT_ID=?
11:19:37,598 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLEXECUTE:49
11:19:37,598 INFO [STDOUT] [Server@3680c1]: 5:SQLCLI:SQLFREESTMT:49
Here is my hibernate.cfg.xml
Code:
<hibernate-configuration>
<session-factory name="java:hibernate/DukesBankSessionFactory">
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="transaction.flush_before_completion">true</property>
<property name="transaction.auto_close_session">true</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost:1701</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<mapping resource="de/msg/dukesbank/integration/hibernate/Customer.hbm.xml"/>
<mapping resource="de/msg/dukesbank/integration/hibernate/Account.hbm.xml"/>
<mapping resource="de/msg/dukesbank/integration/hibernate/Tx.hbm.xml"/>
...
</session-factory>
</hibernate-configuration>
The session Factory is obtained in this way:
Code:
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup("java:hibernate/DukesBankSessionFactory");
} catch (Exception e) {
Log.error(this, "Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException("Could not locate SessionFactory in JNDI");
}
}
I persist entities like
Code:
sessionFactory.getCurrentSession().persist(someBO);