- This topic has 1 reply, 2 voices, and was last updated 17 years, 8 months ago by Riyad Kalla.
-
AuthorPosts
-
seenuMemberi am using hibernate3.0 with hibernate sessionfactory with dao and vo with jndi datasource
and i am using ejb(stateless sessionbean) remoteit was not binding in jndi…..pls solve this
package com.simple.test.hibernate;import java.util.Hashtable;
import java.util.Properties;public class WLSStartup implements T3StartupDef
{
private static final Log log = LogFactory.getLog(WLStartup.class);
public static final String SESSION_FACTORY_JNDI = “MYSQL”;
public static final String URL = “t3://localhost:7001”;/**
* 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.debug ( METHOD_NAME + ” Going to bind Hibernate object. ” );
doBind( );
log.debug ( METHOD_NAME + ” Bound Hibernate object!” );
}
catch ( Exception exception )
{
log.debug ( 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.debug( “Constructing an Initial Directory Context object” );
context = new InitialContext( environment );
/*ds = Hibernate.createDatastore().storeClass(User.class);
Datastore ds = Hibernate.createDatastore();
SessionFactory factory = ds.buildSessionFactory(); */
SessionFactory factory = new Configuration().configure().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;
}}
public void setServices(T3ServicesDef arg0) {
// TODO Auto-generated method stub}
}
/////
i am calling this method in my ejb
public void test() throws EJBException{
SessionFactory sessionFac;
Object objref;
InitialContext context;
///Session session;
///Hibernate.configure();
try {
// The usual WLS JNDI context
//Properties p=System.getProperties();
Hashtable ht=new Hashtable();
context=new InitialContext(ht);
//context = getInitialContext();
System.out.println(“after the context”+context);
//context = getInitialContext();
//objref = context.lookup(WLStartup.SESSION_FACTORY_JNDI);
objref = context.lookup(“MYSQL”);
System.out.println(“SESTest: after the OBJECTREF: “+objref);
sessionFac = (SessionFactory) PortableRemoteObject.narrow(objref, SessionFactory.class);
////sessionFac = (SessionFactory) PortableRemoteObject.narrow(objref, HibernateSessionFactory.class);
System.out.println(“after the OBJECTREF”+sessionFac);
if (sessionFac == null)
throw new Exception(“Null SessionFactory found?!”);
JoblistDAO dao = new JoblistDAO();
System.out.println(“after the dao:”+dao);
dao.findById(“1234”);
System.out.println(“test for dao”+dao);
System.out.println(“……in the test method…..”);
} catch (Exception e) {
System.out.println(“in the test method….” + e.getMessage());
}
/////////////////////
and i am calling this in the client
public static void main(String[] args) throws java.rmi.RemoteException {
// TODO Auto-generated method stub
try {
Properties p = System.getProperties();
Hashtable ht = new Hashtable(p);
ht.put(Context.INITIAL_CONTEXT_FACTORY,”weblogic.jndi.WLInitialContextFactory”);
javax.naming.InitialContext ic = new javax.naming.InitialContext(ht);
Object o = ic.lookup(“ejb/Simplesession”);
System.out.println(“CLIENT: after the jndi object”);
SimplesessionHome h=(SimplesessionHome)javax.rmi.PortableRemoteObject.narrow(o,SimplesessionHome.class);
////SimplesessionHome h = (SimplesessionHome) o;
Simplesession r = h.create();
//HibernateSessionFactory session=new HibernateSessionFactory();
//session=sessionFactory.openSession();
System.out.println(“CLIENT: ” + r.getMessage());
/*JoblistDAO dao=new JoblistDAO();
dao.getSession();
Joblist jv=new Joblist();
jv.setIdno(“1342”);*/
//r.save(jv);
r.test();
////correct method in this////
//Joblist vo=new Joblist(“1234″,”seenu”,”nani”,”ssl”);
//r.insert(vo);
////correct method////
//System.out.println(“”+dao.getSession());
//String s=dao.SESSION_FACTORY_JNDI();
//r.test();
/*JoblistDAO dao = new JoblistDAO();
System.out.println(“CLIENT:Test for dao”+dao);
Joblist jvo = dao.findById(“1235”);
jvo.setActivity(“srinivas”);
jvo.setIdno(“1254”);
jvo.setJobCategory(“srinivas”);
jvo.setJobName(“srinivas”);
System.out.println(“CLIENT: values are saved” + jvo);
r.save(jvo);*/
System.out.println(“Client:”+r);
// JoblistDAO dao=new JoblistDAO();
// dao.findById(“1234”);
// r.findById(“1234”);
// System.out.println(“”+r.findById(“1234”));
// dao.save(jvo);
// Joblist jvo;
// System.out.println(“after the create:”+r.save(jvo));
} catch (Exception e) {
e.printStackTrace();
}
}
////////
it was getting error like this
EJBSession:……..weblogic.ejb20.internal.SessionEJBContextImpl@141e00a
EJBSession: in the setSessionContext …
EJBSession: in the ejbCreate …
EJBSession: in the getMessage …
after the contextjavax.naming.InitialContext@176d662
SESTest: after the OBJECTREF: weblogic.jdbc.common.internal.RmiDataSource@933cba
////in server above was coming
and at the client clide side error is
CLIENT: after the jndi object
CLIENT: hai form get message
java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.NoClassDefFoundError: org.hibernate.SessionFactory
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248)
at com.simple.ejb.Simplesession_wqrcvq_EOImpl_816_WLStub.test(Unknown Source)
at com.simple.simpleclient.SimpleClient.main(SimpleClient.java:37)
Caused by: java.lang.NoClassDefFoundError: org.hibernate.SessionFactory
at com.simple.ejb.Simplesession.test(Simplesession.java:146)
at com.simple.ejb.Simplesession_wqrcvq_EOImpl.test(Simplesession_wqrcvq_EOImpl.java:96)
at com.simple.ejb.Simplesession_wqrcvq_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:491)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:120)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:434)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:429)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
///////
even it was not starting app server and not binding into JNDI( iam using myeclipse )can any one can help me………………………………
Riyad KallaMemberMoving to OT > Soft Dev
-
AuthorPosts