-->
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.  [ 5 posts ] 
Author Message
 Post subject: The problem of hibernate and weblogic
PostPosted: Fri May 28, 2004 10:58 pm 
Newbie

Joined: Tue May 25, 2004 10:02 pm
Posts: 6
hello everyone!
I am a hibernate beginner.I do the program in according to the it.
http://www.hibernate.org/120.html#A7
and
mathaias blog.
http://blogs.atlassian.com/scuttlebutt/ ... 00201.html

My enviroment:
hibernate 2.1.3
os:windows 2000
weblogic v8.1.2

and my config file
hibernate.cfg.xml:
<?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>
<property name="show_sql">true</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.SybaseDialect</property>
<property name="hibernate.connection.datasource">airportdb</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.proxool.pool_alias">pool1</property>
<property name="hibernate.connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="show_sql">true</property>
<property name="hibernate.jdbc.fetch_size">50</property>
<property name="hibernate.jdbc.batch_size">25</property>
<property name="hibernate.jdbc.use_streams_for_binary">true</property>
<property name="hibernate.max_fetch_depth">1</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.session_factory_name">hibernate.session_factory</property>
<property name="hibernate.jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="hibernate.jndi.url">t3://localhost:7001/</property>

<!-- Mapping files -->
<mapping resource="Polayer/HB_DTB.hbm.xml"/>
<mapping resource="Polayer/HB_SCDTB.hbm.xml"/>
<mapping resource="Polayer/YS_DTB.hbm.xml"/>
</session-factory>

</hibernate-configuration>

Hibernatestartup.java

package com.caec;

import java.rmi.*;
import java.util.*;

import javax.naming.*;
import javax.ejb.*;




import weblogic.common.T3StartupDef;
import weblogic.common.T3ServicesDef;

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


public class HibernateStartup implements T3StartupDef
{
public static final String SESSION_FACTORY_JNDI = "hibernate";
public static final String URL = "t3://localhost:7001";



public void setServices(T3ServicesDef services) {}

/**
* Called by WebLogic server upon startup. This is where everything should
* be initialzed.
*
* @param name the JNDI name of this class
* @param args any input parameters
*
* @return the status.
*
* @throws Exception in case of any error
*/

public String startup( String name, Hashtable args ) throws Exception
{
String METHOD_NAME = "startup ";

// Bind the various Hibernate Object to the Weblogic JNDI
try
{
//log( METHOD_NAME + " Going to bind Hibernate object. ");

doBind( );
// log ( METHOD_NAME + " Bound Hibernate object!" );
}
catch ( Exception exception )
{
// log ( METHOD_NAME + " Exception while binding Hibernate Object to Weblogic JNDI" );
exception.printStackTrace ( );
}

return "WLS Startup completed successfully";
}

/**
* Performs Hibernate objects to Weblogic JNDI Namespace bindings.
* It gets the initial context and binds the Hibernate objects to it.
*
* @param None
* @throws Exception in case of any errors
*/

private static void doBind( ) throws Exception
{
Properties environment = null;
InitialContext context = null;

try {
//Properties for storing JNDI configuration information
environment = new Properties();

//Add initial context factory
environment.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
environment.put(Context.PROVIDER_URL, URL);
// log("Constructing an Initial Directory Context object");
context = new InitialContext(environment);

// Configuration cfg = Hibernate.createDatastore();
//net.sf.hibernate.Hibernate.d
Configuration cfg = new Configuration().configure();

SessionFactory factory = cfg.buildSessionFactory();

if (factory == null)
throw new Exception("SessionFactory cannot be built?!");

try {
if (context.lookup(SESSION_FACTORY_JNDI) != null)
context.rebind(SESSION_FACTORY_JNDI, factory);
else
context.bind(SESSION_FACTORY_JNDI, factory);
}
catch (NamingException nameEx) {
context.bind(SESSION_FACTORY_JNDI, factory);
}

}
catch (NamingException nameExp) {
throw new Exception("NamingException: " + nameExp.getMessage());
}
catch (Exception excp) {
throw excp;
}
finally {
if (context != null) {
try {
context.close();
context = null;
}
catch (NamingException nameExp) {
throw new Exception("NamingException for context close: "+ nameExp.getMessage());
}
}
environment = null;
}
}

}


On weblogic console,I can see hibernate's jndi.All console information is right:

10:55:35,452 INFO Environment:462 - Hibernate 2.1.3
10:55:35,502 INFO Environment:496 - loaded properties from resource hibernate.p
roperties: {hibernate.jndi.class=weblogic.jndi.WLInitialContextFactory, hibernat
e.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.show_sql=true,
hibernate.proxool.pool_alias=pool1, hibernate.jdbc.batch_size=25, hibernate.jdb
c.fetch_size=50, hibernate.connection.datasource=airportdb, hibernate.transactio
n.manager_lookup_class=net.sf.hibernate.transaction.WeblogicTransactionManagerLo
okup, hibernate.jndi.url=t3://localhost:7001/, hibernate.cache.use_query_cache=t
rue, hibernate.jdbc.use_streams_for_binary=true, hibernate.max_fetch_depth=1, hi
bernate.session_factory_name=hibernate.session_factory, hibernate.connection.poo
l_size=1, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCachePr
ovider, hibernate.connection.provider_class=net.sf.hibernate.connection.Datasour
ceConnectionProvider, hibernate.cglib.use_reflection_optimizer=true, hibernate.t
ransaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory, hib
ernate.dialect=net.sf.hibernate.dialect.SybaseDialect}
10:55:35,522 INFO Environment:518 - using java.io streams to persist binary typ
es
10:55:35,522 INFO Environment:519 - using CGLIB reflection optimizer
10:55:35,522 INFO Configuration:872 - configuring from resource: /hibernate.cfg
.xml
10:55:35,532 INFO Configuration:844 - Configuration resource: /hibernate.cfg.xm
l
10:55:36,113 INFO Configuration:328 - Mapping resource: Polayer/HB_DTB.hbm.xml
10:55:36,354 INFO Binder:229 - Mapping class: Polayer.HB_DTB -> HB_DTB
10:55:36,504 INFO Configuration:328 - Mapping resource: Polayer/HB_SCDTB.hbm.xm
l
10:55:36,604 INFO Binder:229 - Mapping class: Polayer.HB_SCDTB -> HB_SCDTB
10:55:36,624 INFO Configuration:328 - Mapping resource: Polayer/YS_DTB.hbm.xml
10:55:36,714 INFO Binder:229 - Mapping class: Polayer.YS_DTB -> YS_DTB
10:55:36,714 INFO Configuration:1030 - Configured SessionFactory: null
10:55:36,714 INFO Configuration:613 - processing one-to-many association mappin
gs
10:55:36,714 INFO Configuration:622 - processing one-to-one association propert
y references
10:55:36,714 INFO Configuration:647 - processing foreign key constraints
10:55:36,744 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.SybaseDi
alect
10:55:36,744 INFO SettingsFactory:55 - JDBC result set fetch size: 50
10:55:36,744 INFO SettingsFactory:58 - Maximim outer join fetch depth: 1
10:55:36,744 INFO SettingsFactory:62 - Use outer join fetching: true
10:55:36,744 INFO ConnectionProviderFactory:53 - Initializing connection provid
er: net.sf.hibernate.connection.DatasourceConnectionProvider
10:55:36,754 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming
.provider.url=t3://localhost:7001/, java.naming.factory.initial=weblogic.jndi.WL
InitialContextFactory}
10:55:36,754 INFO DatasourceConnectionProvider:51 - Using datasource: airportdb

10:55:36,754 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.h
ibernate.transaction.JTATransactionFactory
10:55:36,754 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming
.provider.url=t3://localhost:7001/, java.naming.factory.initial=weblogic.jndi.WL
InitialContextFactory}
10:55:36,754 INFO TransactionManagerLookupFactory:38 - instantiating Transactio
nManagerLookup: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
10:55:36,754 INFO TransactionManagerLookupFactory:42 - instantiated Transaction
ManagerLookup
10:55:36,764 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming
.provider.url=t3://localhost:7001/, java.naming.factory.initial=weblogic.jndi.WL
InitialContextFactory}
10:55:36,764 INFO TransactionManagerLookupFactory:38 - instantiating Transactio
nManagerLookup: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
10:55:36,764 INFO TransactionManagerLookupFactory:42 - instantiated Transaction
ManagerLookup
10:55:36,954 INFO SettingsFactory:102 - Use scrollable result sets: true
10:55:36,954 INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): false
10:55:36,954 INFO SettingsFactory:108 - Optimize cache for minimal puts: false
10:55:36,954 INFO SettingsFactory:114 - echoing all SQL to stdout
10:55:36,954 INFO SettingsFactory:117 - Query language substitutions: {no='N',
true=1, yes='Y', false=0}
cache 提供者:net.sf.hibernate.cache.HashtableCacheProvider
10:55:36,954 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.
HashtableCacheProvider
10:55:36,964 INFO Configuration:1093 - instantiating and configuring caches
10:55:37,045 INFO SessionFactoryImpl:119 - building session factory
10:55:37,445 INFO SessionFactoryObjectFactory:86 - Factory name: hibernate.sess
ion_factory
10:55:37,455 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming
.provider.url=t3://localhost:7001/, java.naming.factory.initial=weblogic.jndi.WL
InitialContextFactory}
10:55:37,465 INFO NamingHelper:68 - Creating subcontext: hibernate
10:55:37,465 INFO SessionFactoryObjectFactory:91 - Bound factory to JNDI name:
hibernate.session_factory
10:55:37,465 WARN SessionFactoryObjectFactory:101 - InitialContext did not impl
ement EventContext
10:55:37,465 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming
.provider.url=t3://localhost:7001/, java.naming.factory.initial=weblogic.jndi.WL
InitialContextFactory}
10:55:37,465 INFO UpdateTimestampsCache:35 - starting update timestamps cache a
t region: net.sf.hibernate.cache.UpdateTimestampsCache
10:55:37,475 INFO QueryCache:39 - starting query cache at region: net.sf.hibern
ate.cache.QueryCache
<2004-5-29 上午10时55分38秒 CST> <Notice> <WebLogicServer> <BEA-000331> <Started
WebLogic Admin Server "caserver" for domain "mydomain" running in Development M
ode>
<2004-5-29 上午10时55分38秒 CST> <Notice> <WebLogicServer> <BEA-000360> <Server
started in RUNNING mode>


But I use lookuphibernate.java,the sessionfactory is null.
lookup code:
public Context getInitialContext() throws Exception {

Properties properties;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
properties.put(Context.SECURITY_PRINCIPAL, "weblogic");
properties.put(Context.SECURITY_CREDENTIALS, "weblogic");
return new javax.naming.InitialContext(properties);
}
catch (Exception e) {
System.out.println(
"Unable to connect to WebLogic server at t3://localhost:7001");
System.out.println("Please make sure that the server is running.");
throw e;
}
}

/**
* GetSessionFactory
*/
public void GetSessionFactory() {


Object obref;


try {

Configuration cfg = new Configuration().configure();
Context root = this.getInitialContext();
obref = root.lookup("hibernate");
_sessions = (SessionFactory)PortableRemoteObject.narrow(obref, SessionFactory.class);
if(_sessions == null)
{
throw new Exception("Null SessionFactory found?!");
}
}
catch (Exception ex) {
ex.printStackTrace();
}


}

please help me.
thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 11:26 am 
Newbie

Joined: Tue May 25, 2004 10:02 pm
Posts: 6
Please everyone help me to resolve the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 12:13 pm 
Newbie

Joined: Tue May 25, 2004 10:02 pm
Posts: 6
the code of:
ctx.lookup("")
I have try it in "hibernate"、"hibernate/session_factory"、"hibernate.session_factory"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 10:38 am 
Newbie

Joined: Thu Jun 03, 2004 10:29 am
Posts: 13
I'm having the same problem too. I can see the SessionFactory in the JNDI tree from the Weblogic console and I can see that the object is bound when I pull it from the javax.naming.NameClassPair. But when I do a context.lookup(JNDI_NAME) it always returns null. The java code that I use to do the lookup is good, because I also used it to pull out the javax.sql.DataSource object when getting the SessionFactory failed. It all beats me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 2:00 am 
Newbie

Joined: Tue May 25, 2004 10:02 pm
Posts: 6
Sorry,It is my mistakes.you know,client app and hibernate is two different jvm,so we can not get the sessionfactory forever.
Using Ejb,servlet,It is right.
good luck.


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