-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate with weblogic
PostPosted: Mon Aug 30, 2004 8:56 am 
Beginner
Beginner

Joined: Wed Mar 24, 2004 8:43 am
Posts: 42
Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:

hi all,

could any one pls help me to configure hibernate with weblogic application server,

thx
gimhan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 11:16 am 
Newbie

Joined: Tue Nov 11, 2003 2:27 pm
Posts: 9
I've got an init servlet that sets it up, just have the init() method do it and make sure it's loaded in the web.xml file before the servlets that depend on it. Also, you should be able to stick the config file in your classpath and it should set itself up.


Top
 Profile  
 
 Post subject: Hibernate, Struts, Weblogic Server 8.1
PostPosted: Mon Aug 30, 2004 10:30 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
Weblogic Server 8.1 and Hibernate work very nicely together. Set up your datasource in Weblogic and for the example hibernate config as shown below, configure a data source called 'my.data.source (for example)'.

This example is specifcally geared towards struts users wishing to bind their sesion factory to JNDI with Weblogic Server.


Hibernate.cfg.xml
Code:
  <session-factory name="my.factory.name">
    <!-- Bind the SesssionFactory to JNDI -->

    <!-- JNDI DataSource Connection -->
    <property name="connection.datasource">my.data.source</property>

    <!-- Transaction Management Properties-->
    <property name="transaction.manager_lookup_class">
      net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
    </property>
    <property name="transaction.factory_class">
      net.sf.hibernate.transaction.JTATransactionFactory
    </property>
   
    <!-- Miscellaneous Properties -->
    <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <property name="use_outer_join">true</property>
   
    <!-- mapping files -->
    <mapping resource="a.hbm.xml"/>
    <mapping resource="b.hbm.xml"/>
    <mapping resource="c.hbm.xml"/>
   
  </session-factory>


An adaption of the HibernatePlugin.java found from wiki 105:



Code:
import javax.servlet.ServletException;

import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

public class HibernatePlugin implements PlugIn
{
  private static Log log = LogFactory.getLog(HibernatePlugin.class);
  private static SessionFactory sf = null;

  public void destroy()
  {
    try
    {
      log.info("Closing SessionFactory");
      sf.close();
      log.info("SessionFactory successfully closed");
    }catch(Throwable t)
    {
      log.error("Unbind SesssionFactory failed",t);
    }
  }
 
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException
  {
    try{
      log.info("Initiating bind SessionFactory to JNDI");
      sf = new Configuration().configure().buildSessionFactory();
      log.info("SessionFactory successfully bound to JNDI");     
    }catch(Throwable t)
    {
      log.fatal("Binding SessionFactory to JNDI failed",t);
      throw new ServletException(t);
    }
  }
}


Configure the above class as a plugin in your struts xml or simply use it as the basis for an init type of action. Next thing you know, you're ready to roll with Hibernate and Weblogic server talking to eachother nicely.

To pull your session factory from JNDI you can use the following:

Code:

      Context ctx = new InitialContext();
      SessionFactory sessionFactory = (SessionFactory) ctx.lookup("hibernate.HibernateFactory");



That will at least get you a good push-start.

Good luck,
Joe

_________________
Joe W


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 10:34 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
I made a mistake on the last code block of that last post.

It should be as follows in order to work with the sample hibernate.cfg.xml I showed (This code block is to pull the session factory from jndi):

Code:

      Context ctx = new InitialContext();
      SessionFactory sessionFactory = (SessionFactory) ctx.lookup("my.factory.name");







Also note: the hibernate config that I showed will only work if the config is in its default location. My version of the plugin is not as flexible as the wiki 105 version with regard to specifying plugin parameters.

_________________
Joe W


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.