openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@gmail.com>
Subject Re: A little help with hibernate.cfg.xml and test datasources
Date Thu, 28 Apr 2011 04:20:04 GMT
Hi Andrew!

On Apr 27, 2011, at 6:17 PM, Andrew Hughes wrote:

> Thanks very much!  When I get this all working I think I will submit an new
> example to the project (p.s. distributed version control would be nice).

An example would be great.  There's http://git.apache.org/ if that helps.  I think there is
also a read-only github mirror.

> THANKS FOR ALL YOUR HELP SO FAR! Sorry for bombarding the mailing list with
> these noobie questions...
> 
> Unfortunately I have another problem which I am again in the dark with...
> 
> FATAL - Could not find datasource: *myapp.portal.ds*
> javax.naming.NameNotFoundException: Name "*myapp.portal.ds*" not found.
> at
> org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:193)

As i mentioned on the list, i think the "give hibernate the right initial context" thing is
probably a dead end.  JNDI is not unlike a big hashmap, so how you get it is not nearly as
important as what is inside it and the names they have.

Anyway, the global name for datasources in OpenEJB will be "openejb:Resource/<resource-id>"
(works anywhere OpenEJB is) or "java:openejb/Resource/<resource-id>" (doesn't work in
Tomcat).

All "foo:" names in JNDI do not use use the InitialContextFactory and in fact explicitly bypass
it and use an entirely different JNDI bootstrapping technique (all that logic is in the InitialContext
class itself, not an OpenEJB thing).  So setting the InitialContextFactory in Hibernate will
have no impact at all.

Try this in your hibernate config:

   <property name="hibernate.connection.datasource">openejb:Resource/myapp.portal.ds</property>


-David


> at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:150)
> at
> org.apache.openejb.core.ivm.naming.ContextWrapper.lookup(ContextWrapper.java:115)
> at javax.naming.InitialContext.lookup(InitialContext.java:351)
> at
> org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
> at
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
> at
> org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
> at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
> at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
> at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
> at
> org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
> 
> 
> Either my datasource creation is wrong:
> 
> @BeforeClass
> public static void setUp() throws Exception {
> final Properties p = new Properties();
> p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
> p.put("*myapp.portal.ds*", "new://Resource?type=DataSource");
> p.put("*myapp.portal.ds.JdbcDriver*", SQLServerDriver.class.getName());
> p.put("*myapp.portal.ds.JdbcUrl*",
> System.getProperty("myappPortalDsJdbcUrl"));
> p.put("*myapp.portal.ds.UserName*",
> System.getProperty("myappPortalDsUserName"));
> p.put("*myapp.portal.ds.Password*",
> System.getProperty("myappPortalDsPassword"));
> p.put("*myapp.portal.ds.JtaManaged*", "true");
> context = new InitialContext(p);
> }
> 
> 
> Or the hibernate.cfg.xml's 'hibernate.connection.datasource' is wrong
> (complete hibernate.cfg.xml in initial post for reference):
> 
> 
> <property name="hibernate.connection.datasource">*myapp.portal.ds*
> </property>
> 
> 
> 
> Or I am stuffing up something else I don't know about??? :'(
> 
> 
> CHEERS AND THANKS FOR ALL YOUR HELP SO FAR!
> --AH
> 
> 
> 
> 
> PS. for reference I needed to add the following to my hibernate.cfg.xml to
> fix the javax.naming.NoInitialContextException problem.
> 
> <hibernate-configuration>
>    <session-factory>
>        ....
> *        <property
> name="hibernate.jndi.class">org.apache.openejb.client.LocalInitialContextFactory</property>
> *
>        ....
>    <session-factory>
> </hibernate-configuration>
> 
> 
> 
> 
> On Thu, Apr 28, 2011 at 8:47 AM, djheisterberg <djheisterberg@yahoo.com>wrote:
> 
>> You just need to let hibernate know about
>> org.apache.openejb.client.LocalInitialContextFactory.  Either set it in
>> jndi.properties or in the hibernate config with <property
>> name="hibernate.jndi.class">.
>> 
>> 
>> --
>> View this message in context:
>> http://openejb.979440.n4.nabble.com/A-little-help-with-hibernate-cfg-xml-and-test-datasources-tp3477192p3479695.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>> 


Mime
View raw message