-->
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.  [ 8 posts ] 
Author Message
 Post subject: standalone app & xml-config
PostPosted: Wed Nov 05, 2003 1:31 pm 
Newbie

Joined: Wed Sep 17, 2003 8:26 am
Posts: 16
hi all,

i have a small standalone-app that is using hibernate. i configure hibernate using a xml file. how can i get rid of the following exception:

2003-11-05 18:18:55,318 WARN - Could not bind factory to JNDI - at net.sf.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:98)
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

tia,

jan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 4:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do not set hibernate.session_factory_nameproperty, you're not using JNDI

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 4:54 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
If you cut'n'pasted example XML config, remove "name=..." from

<session-factory
name="java:comp/env/hibernate/SessionFactory">


Top
 Profile  
 
 Post subject: Are you using tomcat? If so java:comp/env is read-only
PostPosted: Wed Nov 05, 2003 7:01 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I had this problem Monday but, at that time, I knew NOTHING about JNDI. It turns out that for Tomcat (I'm on v4.1.24) the Context name they gave is read-only: "java:/comp/env". It took me a few hours before I got the brains (read: duh!) to try another context. I made up the name:
"dgf:/hibernate/SessionFactory" such as:
<session-factory name="dgf:/hibernate/SessionFactory">

Wouldn't you know it, Hibernate has the brains to create that context for you and store itself in there. I accessed it with this code snippet:

==========================================
Context ctx;
SessionFactory sf;

try {
ctx = new InitialContext();
ctx = (Context) ctx.lookup("dgf:/hibernate");
sf = (SessionFactory) ctx.lookup("SessionFactory");
} catch (
} catch (NamingException ne) {
log.info("Y1, Context exception: " + ne.getMessage());
} catch (HibernateException he) {
log.info("Y2: Hibernate exception: " + he.getMessage());
}
==========================================

Why did I do this? So I could create a facade for Hibernate 2.0.3 under Struts 1.1 without passing references to the Session, SessionFactory, or the request or application context back and forth. Now, I just create the object, have it reconnect before the transaction, disconnect after the transaction, and never need to hand it the Session, SessionFactory, request, or servletContext. It's a bit more convenient for me this way to just create an SQL class object and say sql.load(whatever).

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 7:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jan is in a standalone application. No JNDI at all

_________________
Emmanuel


Top
 Profile  
 
 Post subject: no jndi
PostPosted: Thu Nov 06, 2003 3:43 am 
Newbie

Joined: Wed Sep 17, 2003 8:26 am
Posts: 16
yep, there is _no_ jndi and according to the dtd i have to set a name in the sessionfactory-tag. if i remove it, hibernate complains about the missing attribute.

jan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 3:46 am 
Newbie

Joined: Wed Sep 17, 2003 8:26 am
Posts: 16
and btw, it is plain hibernate 2.0. perhaps the name-attr. isn't mandatory in later versions? anyway - i can not update to another hibernate version now.

jan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 7:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This has been corrected since 2.0 beta 4!
This is a warning log, may work despite this problem.

_________________
Emmanuel


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