You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by jaigates <ja...@gmail.com> on 2013/04/23 16:57:17 UTC

how to add datasource for openejb in jndi.properties

i am using openejb as ejb/jee unit testing framework in my application for
several months and working fine with jboss soa-p 5.3 (jboss eap 5.x/jboss as
5.1). I am using hibernate as jpa provider.


Recently in one of my service dao i added a line like below for dynamically
creating persistent unit.

code:
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("perunit");

in persistent.xml:

	<persistence-unit name="perunit"> 
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>teiidDS</jta-data-source>
		
		<class>xxx.CountryE</class>

		<properties>
			<property name="hibernate.dialect" value="org.teiid.dialect.TeiidDialect"
/>
			<property name="connection.autocommit" value="false" />
			<property name="hibernate.show_sql" value="true" />
		</properties>

	</persistence-unit>

For testing purpose i have overriden datasource :teiidDS in jndi.properties
like

jndi.properties:

teiidDS=new://Resource?type=DataSource
teiidDS.JdbcDriver=oracle.jdbc.driver.OracleDriver
#teiidDS.JtaManaged=true
teiidDS.UserName=<<userbname>>
teiidDS.Password=<<password>>

perunit.provider=org.hibernate.ejb.HibernatePersistence
perunit.JdbcDriver=oracle.jdbc.driver.OracleDriver
perunit.JdbcUrl=<<jdbc url>>
perunit.JtaManaged=true
perunit.UserName=<<username>>
perunit.Password=<password>>
perunit.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
perunit.hibernate.connection.url=<<jdbc url>>


when i execute a testcase which all my service it thorws below exception 


INFO - Deployed Application(path=classpath.ear)
javax.persistence.PersistenceException: Provider error. Provider:
org.hibernate.ejb.HibernatePersistence
	at javax.persistence.Persistence.createFactory(Persistence.java:176)
	at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112)
	at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:66)
	at
org.ibo.globalapi.ejb.test.EntityManagerTest.TestRuntimeJPAEntityManger(EntityManagerTest.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit:
ibo-ejb] Unable to build EntityManagerFactory
	at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
	at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
	at javax.persistence.Persistence.createFactory(Persistence.java:172)
	... 26 more
Caused by: org.hibernate.HibernateException: Could not find datasource
	at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
	at
org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
	at
org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
	at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
	at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
	at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
	... 28 more
Caused by: javax.naming.NameNotFoundException: Name "teiidDS" not found.
	at
org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:193)
	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:411)
	at
org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
	... 35 more



When i inspect the InitialContext
(org.apache.openejb.client.LocalInitialContextFactory), i am not able to
lookup any objects other than ejb's. Let me know how to acheive this in
openejb



--
View this message in context: http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how to add datasource for openejb in jndi.properties

Posted by Romain Manni-Bucau <rm...@gmail.com>.
so you need to set it to resource_local and use  <non-jta-data-source> +
use java:openejb/Resource/<ds name> name if you don't want to get it
injected

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/23 jaigates <ja...@gmail.com>

> yes
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662405.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: how to add datasource for openejb in jndi.properties

Posted by jaigates <ja...@gmail.com>.
yes



--
View this message in context: http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662405.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how to add datasource for openejb in jndi.properties

Posted by Romain Manni-Bucau <rm...@gmail.com>.
so you need a RESOURCE_LOCAL persistence.xml, not a JTA one, not sure i
really follow you

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/23 jaigates <ja...@gmail.com>

> no, i am afraid my requrement is not completely understood. i cannot do any
> annotation here.
>
> i would pass persistant unit name during runtime and my service should get
> its entitymanager object during runtime.
>
> actual code is :
>
> method(string entityManagerName){
> ...
> EntityManagerFactory emf =
> Persistence.createEntityManagerFactory(entityManagerName);
> ...
> }
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662403.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: how to add datasource for openejb in jndi.properties

Posted by jaigates <ja...@gmail.com>.
no, i am afraid my requrement is not completely understood. i cannot do any
annotation here.

i would pass persistant unit name during runtime and my service should get
its entitymanager object during runtime.

actual code is :

method(string entityManagerName){
...
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(entityManagerName);
...
}



--
View this message in context: http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662403.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how to add datasource for openejb in jndi.properties

Posted by Romain Manni-Bucau <rm...@gmail.com>.
@PersistenceUnit in a bean or in the test class if started with arquillian
or EJBContainer

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/23 jaigates <ja...@gmail.com>

> i understood ic.lookup("java:/openejb/Resource/teiidDS") i get the
> datasource
> object.
> But my requirement is to get persistentunit, how to do this?
>
> or else, what modifications i need to do in y jndi.properties to acheive
> this ?
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662400.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: how to add datasource for openejb in jndi.properties

Posted by jaigates <ja...@gmail.com>.
i understood ic.lookup("java:/openejb/Resource/teiidDS") i get the datasource
object.
But my requirement is to get persistentunit, how to do this?

or else, what modifications i need to do in y jndi.properties to acheive
this ?




--
View this message in context: http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398p4662400.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how to add datasource for openejb in jndi.properties

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

this sample
http://svn.apache.org/repos/asf/tomee/tomee/trunk/examples/jpa-hibernate/ does
it

you probably have an issue getting the resource (in openejb:Resource/<ds
name>)

can you share a sample reproducing it?

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/23 jaigates <ja...@gmail.com>

>
> i am using openejb as ejb/jee unit testing framework in my application for
> several months and working fine with jboss soa-p 5.3 (jboss eap 5.x/jboss
> as
> 5.1). I am using hibernate as jpa provider.
>
>
> Recently in one of my service dao i added a line like below for dynamically
> creating persistent unit.
>
> code:
> EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("perunit");
>
> in persistent.xml:
>
>         <persistence-unit name="perunit">
>                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
>                 <jta-data-source>teiidDS</jta-data-source>
>
>                 <class>xxx.CountryE</class>
>
>                 <properties>
>                         <property name="hibernate.dialect"
> value="org.teiid.dialect.TeiidDialect"
> />
>                         <property name="connection.autocommit"
> value="false" />
>                         <property name="hibernate.show_sql" value="true" />
>                 </properties>
>
>         </persistence-unit>
>
> For testing purpose i have overriden datasource :teiidDS in jndi.properties
> like
>
> jndi.properties:
>
> teiidDS=new://Resource?type=DataSource
> teiidDS.JdbcDriver=oracle.jdbc.driver.OracleDriver
> #teiidDS.JtaManaged=true
> teiidDS.UserName=<<userbname>>
> teiidDS.Password=<<password>>
>
> perunit.provider=org.hibernate.ejb.HibernatePersistence
> perunit.JdbcDriver=oracle.jdbc.driver.OracleDriver
> perunit.JdbcUrl=<<jdbc url>>
> perunit.JtaManaged=true
> perunit.UserName=<<username>>
> perunit.Password=<password>>
> perunit.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
> perunit.hibernate.connection.url=<<jdbc url>>
>
>
> when i execute a testcase which all my service it thorws below exception
>
>
> INFO - Deployed Application(path=classpath.ear)
> javax.persistence.PersistenceException: Provider error. Provider:
> org.hibernate.ejb.HibernatePersistence
>         at
> javax.persistence.Persistence.createFactory(Persistence.java:176)
>         at
>
> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112)
>         at
>
> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:66)
>         at
>
> org.ibo.globalapi.ejb.test.EntityManagerTest.TestRuntimeJPAEntityManger(EntityManagerTest.java:18)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:601)
>         at
>
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>         at
>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at
>
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>         at
>
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>         at
>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>         at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: javax.persistence.PersistenceException: [PersistenceUnit:
> ibo-ejb] Unable to build EntityManagerFactory
>         at
>
> org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
>         at
>
> org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
>         at
> javax.persistence.Persistence.createFactory(Persistence.java:172)
>         ... 26 more
> Caused by: org.hibernate.HibernateException: Could not find datasource
>         at
>
> org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
>         at
>
> org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
>         at
>
> org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
>         at
> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
>         at
> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
>         at
>
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
>         at
>
> org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
>         at
>
> org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
>         ... 28 more
> Caused by: javax.naming.NameNotFoundException: Name "teiidDS" not found.
>         at
> org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:193)
>         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:411)
>         at
>
> org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
>         ... 35 more
>
>
>
> When i inspect the InitialContext
> (org.apache.openejb.client.LocalInitialContextFactory), i am not able to
> lookup any objects other than ejb's. Let me know how to acheive this in
> openejb
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-to-add-datasource-for-openejb-in-jndi-properties-tp4662398.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>