-->
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.  [ 2 posts ] 
Author Message
 Post subject: I'm careless .... its working :)
PostPosted: Thu Dec 04, 2003 6:21 pm 
Newbie

Joined: Wed Dec 03, 2003 11:50 am
Posts: 7
Location: Texas
It seems that my source class is now working. It turns out that my source code was not in synch with what was deployed. The final "bind" step was indeed causing the error. To anyone who wants to push my source to the Wiki for "pounding/testing". Below is the source/configs combinations.

Included is:
    Java Source
    Hibernate Config XML File
    DataSource Name


Here is the source:
Code:
/*
* Created on Dec 1, 2003 By Scott Cote
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.*;

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

import org.apache.commons.logging.*;

import weblogic.common.T3StartupDef;
import weblogic.common.T3ServicesDef;
/**
* @author nbku21j
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Startup implements T3StartupDef {
   
  private static final Log log = LogFactory.getLog(Startup.class);
  public static final String SESSION_FACTORY_JNDI = "hibernate";
  public static final String URL = "t3://localhost:7001";
 
  private T3ServicesDef aT3ServicesDef;
  private Hashtable someStartupArgs;
 
  /**
   *
   */
  public Startup() {
       LogFactory.getFactory().setAttribute(SESSION_FACTORY_JNDI, someStartupArgs);
  }

  /* (non-Javadoc)
   * @see weblogic.common.T3StartupDef#setServices(weblogic.common.T3ServicesDef)
   */
  public void setServices(T3ServicesDef _T3ServicesDef) {
    // TODO Auto-generated method stub
    this.aT3ServicesDef = _T3ServicesDef;
  }

  /* (non-Javadoc)
   * @see weblogic.common.T3StartupDef#startup(java.lang.String, java.util.Hashtable)
   */
  public String startup(String _virtualName, Hashtable _startupArgs) throws Exception {
    // TODO Auto-generated method stub
    log.info(new StringBuffer("Attempting to bind Hibernate 2.1 Session Factory to JNDI ... ")
      .append(_virtualName).toString());
    doBind(_startupArgs);
    return "Hibernate 2.1 Session Factory successfully bound to WebLogic JNDI";
  }
 
  private void doBind(Hashtable _startupArgs) throws Exception {
    InitialContext context = null;
    Context wlsContext = null, subContext = null;
    SessionFactory factory = null;
   
    try {
      
     log.info("Updating the startup args for the weblogic context object");
     _startupArgs.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
     _startupArgs.put(Context.PROVIDER_URL, URL);
     log.info("Retrieving the weblogic Initial context");
     wlsContext =  this.aT3ServicesDef.name().getInitialContext();
    
     log.info("Creating subcontext called: hibernate");
     subContext = wlsContext.createSubcontext("hibernate");
     log.info("Closing the newly created subcontext.");
     subContext.close();
     log.info("Building the session factory");
     factory = new Configuration().configure().buildSessionFactory();
              log.info("Built the session factory - hibernate is bound to JNDI");    
    } catch (NamingException eN) {
     //throw new Exception( "NamingException: " + eN.getMessage( ));
     eN.printStackTrace();
     throw eN;
    } finally {
      if (context != null) {
         try {
            context.close();
            context = null;
         } catch (NamingException eNFinally) {
            throw new Exception(new StringBuffer("NamingException for context close: ").append(eNFinally.getMessage()).toString());
         }
      }
    }
  }

}


The hibernate xml configuration file:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory name="hibernate/SessionFactory">
        <property name="connection.datasource">jdbc/quickstart</property>
        <property name="show_sql">true</property>       
        <property name="use_outer_join">true</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
        <property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
        <!-- Mapping files -->
        <mapping resource="Cat.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


The Data Source Name: "jdbc/quickstart"

If anyone tries my class, please let me know if it works on your environment. Hopefully, it can be used to "update" the Wiki for how to deal with Weblogic.

SCott


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 6:28 pm 
Newbie

Joined: Wed Dec 03, 2003 11:50 am
Posts: 7
Location: Texas
BTW - This is a continuation of the thread http://forum.hibernate.org/viewtopic.php?p=2181042#2181042

SCott


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