Hello,
I am trying to get a handle on using hibernate, from all i have read it looks like an awsome tool. We have 4 sites that are currently using standard SQL calls that i would like to move over to hibernate.
These sites currently run on the same jboss deployment and are setup for virtual name based hosting as per http://jboss.org/index.html?module=bb&op=viewtopic&t=10830
I have followed all of the examples from 66.html as well as the linked docs. Hibernate gets installed as an SAR with no problem.
My question is -
since i have deployed hibernate as a SAR with this as the jboss-service.xml which was generated via the ant script
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>
<attribute name="MapResources">omni/user/UserBean.hbm.xml,omni/user/AddressBean.hbm.xml,omni/user/ProfileBean.hbm.xml</attribute>
<attribute name="JndiName">HibernateFactory</attribute>
<attribute name="Datasource">MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="UseOuterJoin">true</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>
</mbean>
</server>
Do I still need to provide access to hibernate using the HibernateUtil class or should i be able to access hibernate from jndi? This may should like a silly question, but I want to make sure I understand fully before we begin to move over to a new technology
Here is the HibernateUtil class i am using in our tests.Code:
public class HibernateUtil {
static Category log = Category.getInstance(HibernateUtil.class.getName());
private static SessionFactory sessionFactory;
static {
try {
sessionFactory =
new Configuration().configure().buildSessionFactory();
}
catch (HibernateException ex) {
log.error("caught: " +ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
Any pointers or recommendations would be of great help
Happy New Year!
Jason