I don't understand how the deployment descriptor you posted relates to your CMP problem.
If you want to use CMP (container managed persistence) then you have to write an entity bean, not a session bean.
An entity bean needs to have its ejb-jar.xml descriptor and can have two further jboss descriptors called jboss.xml and jbosscmp-jdbc.xml.
These file-formats are explained within the docs/dtd/html-svg directory of the jboss distribution.
If you're problem is that you cannot access a database from within your current session-bean, then it might be due to the fact that you did not declare a jdbc-datasource within the above deployment descriptor.
I don't understand how the deployment descriptor you posted relates to your CMP problem...
I mean CMT (Container Managed Transaction), not CMP.
ah, ok. my mistake. them abbrevations...
I'm not an *expert* on CMT, CMP & Jboss, but there is nothing further
you need to do to use CMT than configuring it within ejb-jar.xml
You don't have to specify further options in any other descriptor.
To me, it seems as if your ejb.jar.xml descriptor looks fine. It has the transaction-type set to container and the trans-attribute set to Required.
That's fine. Now any method is wrapped in a single transaction that commits when the method ends, unless you have called setRollbackOnly() or whatever the name is...
Hmm, since you're deployment descriptor does not contain a resource-ref section, I wonder what kind of database API you are working with. Maybe the transaction context is not passed on to the DB manager you are using.
You could try to look at the transaction logs of your database to see whether a rollback occurs. And you could switch on call-logging in jboss to see if the transaction is rolled back inside JBoss.
However, are you sure that CMT is the cause of your problem?
Do your database calls succeed if you use BMT instead?
Your statement that no rollback exception is thrown means that the transaction completed successfully within JBoss.
Maybe the problem lies elsewhere.
Concerning CMT, I would recommend to use the standard jdbc Datasource mechanism. I believe, JBoss can pass on the transaction context to those types of resource managers known within the J2EE world.
can you provide me with more information?
what kind of persistence mechanism are you using?
why does your descriptor not contain a resource-ref section?
Is the DB code directly inside your MpBean or inside another bean that the MpBean calls?
ah, ok. my mistake. them abbrevations...
First of all let me thank you for so detailed reply.
Now, I'm using Hibernate as my persistence layer. I have my business methods in classes.
I want to have a service layer with Session Beans to execute those business methods and have CMT control my transactions.
I've deployed Hibernate as a SAR with the following jboss-service.xml:
<server> <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=ArsolHibernateFactory, name=ArsolHibernateFactory"> <depends>jboss.jca:service=RARDeployer</depends> <depends>jboss.jca:service=LocalTxCM,name=arsolDS</depends> <!-- Make it deploy ONLY after DataSource had been started --> <attribute name="MapResources"> mapping/ArmazemMistura.hbm.xml, mapping/ArmazemMp.hbm.xml, mapping/ArmazemPa.hbm.xml, mapping/ArmazemPeca.hbm.xml </attribute> <attribute name="JndiName">java:/hibernate/ArsolHibernateFactory</attribute> <attribute name="Datasource">java:/arsolDS</attribute> <attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute> <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute> <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute> <attribute name="UseOuterJoin">false</attribute> <attribute name="ShowSql">false</attribute> <attribute name="UserTransactionName">UserTransaction</attribute> </mbean> </server>
Here's my datasource:
<?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>arsolDS</jndi-name> <connection-url>jdbc:postgresql://localhost:5432/devdb</connection-url> <driver-class>org.postgresql.Driver</driver-class> <user-name>user</user-name> <password>pwd</password> </local-tx-datasource> </datasources>
Apparently, everithing gets deployed with no errors.
The SAR above is working for a trasaction-per-method style. Now I want to use CMT with Session Beans.
Any ideas please?
I know hibernate but have never used it, so I cannot help you, but since the JBoss Group is pretty much into it, I suppose that you have chances to get help from someone on this forum.
What I'd do:
- turn on logging in debug mode for the respective JDBCDriver and hibernate packages to see what exactly goes wrong, or alternatively look at the Postgres logs to see whether anythings hits your database system at all.
That way you should be able to find out whether or not a rollback appears.