-->
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: Accessing SessionFactory through JNDI from J2SE app
PostPosted: Tue Oct 11, 2005 8:31 pm 
Beginner
Beginner

Joined: Mon Sep 05, 2005 4:48 pm
Posts: 31
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:

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

Full stack trace of any exception that occurs:
[java] org.hibernate.HibernateException: Could not find datasource
[java] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
[java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
[java] at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:313)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:112)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1509)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
[java] at ami.server.ejb.HibernateUtil.<clinit>(HibernateUtil.java:37)
[java] at ami.server.datamart.billing.AggregationTestCase.testDailyAggregation(AggregationTestCase.java:89)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at junit.framework.TestCase.runTest(TestCase.java:154)
[java] at junit.framework.TestCase.runBare(TestCase.java:127)
[java] at junit.framework.TestResult$1.protect(TestResult.java:106)
[java] at junit.framework.TestResult.runProtected(TestResult.java:124)
[java] at junit.framework.TestResult.run(TestResult.java:109)
[java] at junit.framework.TestCase.run(TestCase.java:118)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.textui.TestRunner.doRun(TestRunner.java:116)
[java] at junit.textui.TestRunner.start(TestRunner.java:172)
[java] at junit.textui.TestRunner.main(TestRunner.java:138)
[java] Caused by: javax.naming.NameNotFoundException: MySqlDS not bound


Name and version of the database you are using:
MySQL 4.1.14


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I am attempting to access a SessionFactory through JNDI within a standalone J2SE class, and I keep getting the exception "org.hibernate.HibernateException: Could not find datasource . . . Caused by: javax.naming.NameNotFoundException: MySqlDS not bound"

Based on the documentation I have read, I am of the understanding that the properties from the default hibernate.cfg.xml file(which I am using) are loaded into the context at the time of the "buildSessionFactory();" call. However, I am still getting the "not bound" error. I don't understand why this exception would be thrown at the point where the properties are being loaded to the context. Am I just missing something simple here?

Here is the code from HibernateUtil.java:

<b>static {
try { configuration = new Configuration(); sessionFactory = configuration.configure("hibernate.cfg.xml").buildSessionFactory(); parallelConfiguration = new Configuration();
parallelSessionFactory = parallelConfiguration.configure("hibernateParallel.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// We have to catch Throwable, otherwise we will miss
// NoClassDefFoundError and other subclasses of Error
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
</b>

I have a JBoss instance running, but I want to access the SessionFactory from outside the app-server JNDI tree. This should be possible seeing that the InitialContext may span multiple JVMs.

Is it even possible to access the SessionFactory by way of JNDI outside of the web-ejb container?

Thanks in advance!

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 10:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
JBoss data sources are not accessible outside the server in which they are defined, afaik.

In any case, the exception you are getting has to do with not being able to locate a data source; nothing to do with the session factory being accessible or not.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 10:53 am 
Beginner
Beginner

Joined: Mon Sep 05, 2005 4:48 pm
Posts: 31
Steve:

Thank you for the prompt reply! Let me put this another way . . . what would be your suggestion as to the most efficient and practical way to obtain a SessionFactory from a standalone J2SE class when I want to access the JNDI tree from my JBoss app server instance. The JBoss server uses the standard mbean service to handle the JNDI setup.

Does that make sense?

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 11:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
what do you mean by
Quote:
The JBoss server uses the standard mbean service to handle the JNDI setup.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 12:58 pm 
Beginner
Beginner

Joined: Mon Sep 05, 2005 4:48 pm
Posts: 31
I was referring to the JBossNS JNDI Implementation. I found the following exerpt from the JBoss JNDI Doc section:

An application component environment is a local environment that is accessible only by the component when the application server container thread of control is interacting with the application component. This means that an EJB Bean1 cannot access the ENC elements of EJB Bean2, and visa-versa. Similarly, Web application Web1 cannot access the ENC elements of Web application Web2 or Bean1 or Bean2 for that matter. Also, arbitrary client code, whether it is executing inside of the application server VM or externally cannot access a component's java:comp JNDI context. The purpose of the ENC is to provide an isolated, read-only namespace that the application component can rely on regardless of the type of environment in which the component is deployed. The ENC must be isolated from other components because each component defines its own ENC content. Components A and B, for example, may define the same name to refer to different objects. For example, EJB Bean1 may define an environment entry java:comp/env/red to refer to the hexadecimal value for the RGB color for red, while Web application Web1 may bind the same name to the deployment environment language locale representation of red

Notice the part regarding arbitrary client code here . . . although I am not sure this pertains to me because the binding name I am attempting to obtain is not at java:comp.

Again, basically all I need to do is figure out a way to grab these JNDI bindings by way of an InitialContext in a client app once they are bound through the JBoss service in the App Server.

Mark


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.