-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: hibernate 2.1 + jboss 3.2.2 w/ Tomcat and MySql config
PostPosted: Tue Dec 30, 2003 2:41 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can access the SessionFactory using JNDI. So in your util class you can replace

Code:
         sessionFactory =
            new Configuration().configure().buildSessionFactory();

With a JNDI Lookup


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 3:13 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
awesome! thanks for the pointer...

cheers...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.