-
1. Re: can not find UserTransaction
adrian.brock Apr 14, 2004 1:41 PM (in response to autocrab)You have configured your bean as BMT?
Come on show some details, not "IT DOES NOT WORK" -
2. Re: can not find UserTransaction
autocrab Apr 14, 2004 10:10 PM (in response to autocrab)I have add mysql-connector-java-3.0.11-stable-bin.jar under JBOSS_HOME\server\default\lib and mysql-ds.xml under JBOSS_HOME\server\default\deploy,
the hibernatecfg.xml is<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <!-- a SessionFactory instance listed as /jndi/name --> <session-factory> <!-- properties --> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property> <property name="connection.datasource">java:/MySqlDS</property> <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property> <property name="cache.use_query_cache">true</property> <property name="cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property> <!-- mapping files --> <mapping resource="******.hbm.xml"/> ...... </session-factory> </hibernate-configuration>
-
3. Re: can not find UserTransaction
autocrab Apr 14, 2004 10:12 PM (in response to autocrab)It seems i configured my bean as BMT
-
4. Re: can not find UserTransaction
adrian.brock Apr 15, 2004 6:06 AM (in response to autocrab)Seems is ok then. I'll just have to take word for it.
You'll also have to take word for it that I can't help you without seeing what you doing.
What makes you think Hibernate configuration has anything to do with BMT
or user transactions? It is not a part of any j2ee spec.
Your lack of ability to show relevent information leads me to conclude you have
no idea what you are doing.
Regards,
Adrian -
5. Re: can not find UserTransaction
autocrab Apr 15, 2004 8:35 AM (in response to autocrab)I really want to say thank you first. Let me make the context more clearly.
My high level architectural flow :
Stateless session bean -> Hibernate -> mysql data source ->database.
I congfigured datasource in JBoss, and use the datasource in hibernate to connect to MySQL.
I’ve a stateless session bean to handle my data layer operations. Once when I’ve the local-tx-datasource and when I do
Session session = HibernateSessionFactory.openSession();
...
tx = session.beginTransaction();
...
tx.commit();
This is style for JDBCTransaction(BMT), so i changed my hibernate.cfg.xml, replace<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
with<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
, it is ok when i start JBoss, but when use call the bean to do some database opertion, the JBoss will print out
exceptions15:13:21,695 ERROR [JDBCTransaction] Commit failed java.sql.SQLException: You cannot commit during a managed transaction! at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:400) at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:477) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:63) ...
.
The situation is the hibernate connect to database through datasource which is configured in JBoss, whether I can use JDBCTransaction
as above? If I can use JDBCTransaction in this situation, what may cause the "Commit failed" error, and what may be the possible solution.
If not, must I use CMT, and let container to manager the transaction?
I am newbie to both JBoss and Hibernate, I may be not clear with some conceptions related. Thanks! -
6. Re: can not find UserTransaction
adrian.brock Apr 15, 2004 8:52 AM (in response to autocrab)Whether you are using CMT or BMT,
you cannot invoke commit() explicitly.
This is handled by the transaction commit not you.
If you don't want the connection to be part of the managed transaction
you should use<no-tx-datasource>
-
7. Re: can not find UserTransaction
adrian.brock Apr 15, 2004 9:09 AM (in response to autocrab)Or don't start the user transaction in the first place.
-
8. Re: can not find UserTransaction
autocrab Apr 15, 2004 10:09 AM (in response to autocrab)The fact is that, when I configure the hibernate.cfg.xml without using the jndi for datasource, but directly"jdbc:mysql://localhost:3306/***", my application works ok. I want to configure a connection pool in JBoss to tuning the proformance. so i have to use datasource.
If i comment off the code,likeSession session = HibernateSessionFactory.openSession(); ... //tx = session.beginTransaction(); ... //tx.commit();
There is another problem, i can operate the object made in the transaction only once, i can not modify or delete the object later, which seems as if the transaction is not end, i can not commit any more. -
9. Re: can not find UserTransaction
adrian.brock Apr 15, 2004 10:24 AM (in response to autocrab)Did you even read my previous comment.
no-tx-datasource is exactly like direct jdbc access - except with pooling
Any work you do is not part of the JTA tranasction.
If you want further help, you need to show how you are using the session
and state which of the different configurations of hibernate that you have already posted
you are actually using.
You also need to post FULL exceptions not "It does not work".
Please have a look at the "READ ME FIRST" topic in this forum.
I am not going to play ping/pong with you anymore.
Regards,
Adrian -
10. Re: can not find UserTransaction
adrian.brock Apr 15, 2004 10:31 AM (in response to autocrab)You might also be interested in this link if you want to learn how it works.
http://www.hibernate.org/175.html
This forums is for technical question, not hand holding or free consulting. -
11. Re: can not find UserTransaction
autocrab Apr 15, 2004 9:25 PM (in response to autocrab)I very appreciate your quick feedback. Yesterday, I misundertood the code
<no-tx-datasource>
. Just now, I tried, replaced<local-tx-datasoure>
with<no-tx-datasource>
, and my application works ok.
Thank you very much.