Hello,
I'am using Hibernate Version 2.1 with JBoss 3.2.3 as MBean service. In a 3 Tier application I want to use CMT Stateless-Session-Beans as facade for the Hibernate persistencelayer. This works so far, but I'am not sure if I'am using the MBean Service correctly.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<!-- Generated file - Do not edit! -->
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySQLDS</depends>
<attribute name="MapResources">de/fh_brs/inf/helpdesk/business/hibernate/EditorHibernate.hbm.xml,de/fh_brs/inf/helpdesk/business/hibernate/TroubleTicketHibernate.hbm.xml</attribute>
<attribute name="JndiName">hibernate</attribute>
<attribute name="Datasource">java:/MySQLDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
</mbean>
</server>
Code:
/**
* @ejb.bean
* display-name="EditorHibernateFacade"
* jndi-name="ejb/EditorHibernateFacade"
* name="EditorHibernateFacade"
* type="Stateless"
* view-type="remote"
*
* @ejb.transaction
* type = "Required"
*
* @ejb.util
* generate = "physical"
*/
public abstract class EditorHibernateFacadeBean implements SessionBean {
/**
* @ejb.interface-method
*/
public Editor create(String name) throws NamingException, HibernateException {
InitialContext context = new InitialContext();
Object obj = context.lookup("hibernate");
SessionFactory factory = (SessionFactory) obj;
Session session = factory.openSession();
Transaction trans = session.beginTransaction();
EditorHibernate editor = new EditorHibernate();
editor.setName(name);
session.save(editor);
trans.commit();
session.close();
return editor;
}
}
My Question is, if I need to create the Hibernate transaction or if it is implicit created in the session because I'am using CMT.
Thank you!
Alexander Kirsch