Hi Antonio,
Could you please clarify whether it worked when it was deployed in
GlassFish Server mode ?
Earlier email in the thread stated that it worked fine in GF 3.1.1 b12.
Thanks,
-Jagadish
On Fri, 2012-01-06 at 08:55 +0100, Antonio Goncalves wrote:
> Indeed, it works if I move the @DataSourceDefinition into the ItemEJB.
> It is a shame because having the @DSD on a CDI bean should be
> encourage (once https://issues.jboss.org/browse/CDI-53 is solved we
> will be able to have several @DataSourceDefinition with
> alternatives).
>
>
> In the meantime in the Java EE 6 spec (EE.5.17 - DataSource Resource
> Definition) it is written "A DataSource resource may also be defined
> using the DataSourceDefinition annotation on a container-managed
> class, such as a servlet or enterprise bean class." A CDI bean is a
> container-managed class so this should work. Don't you think ?
>
>
> Antonio
>
> 2012/1/6 Mitesh Meswani <mitesh.meswani_at_oracle.com>
> Hi Anotonio,
>
> We have a dev test that exercise similar combination and it is
> passing. The only difference being the dev test does not use
> CDI. Can you try putting the @DSD annnotation on your
> @Stateless bean to see if this works.
>
> Thanks,
> Mitesh
>
> On 1/5/2012 7:08 AM, Antonio Goncalves wrote:
> > BTW, same thing happens with 3.1.2-b14 : works within
> > GlassFish, doesn't work in embedded mode
> >
> >
> > Antonio
> >
> > 2012/1/5 Antonio Goncalves <antonio.mailing_at_gmail.com>
> > Hi,
> >
> >
> > I'm using @DataSourceDefinition to define a
> > datasource. This works fine when I run it with
> > GlassFish 3.1.1-b12 but doesn't when I run a test
> > using the embedded mode (with EJBContainer). These
> > are my classes :
> >
> >
> > DatabaseResource defines a Derby in memory
> > datasource and produces an EntityManager
> >
> >
> > @DataSourceDefinition(name =
> > "java:app/jdbc/sampleArquilianWytiwyrDS",
> > className =
> > "org.apache.derby.jdbc.EmbeddedDriver",
> > url =
> > "jdbc:derby:memory:sampleArquilianWytiwyrDB;create=true;user=app;password=app"
> > )
> > public class DatabaseResource {
> >
> >
> > @Produces
> > @PersistenceContext(unitName =
> > "sampleArquilianWytiwyrPU")
> > private EntityManager em;
> > }
> >
> >
> > The persistence.xml uses this datasource :
> >
> >
> > <persistence
> > xmlns="http://java.sun.com/xml/ns/persistence"
> >
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >
> > xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
> > version="2.0">
> > <persistence-unit
> > name="sampleArquilianWytiwyrPU"
> > transaction-type="JTA">
> >
> > <jta-data-source>java:app/jdbc/sampleArquilianWytiwyrDS</jta-data-source>
> >
> > <class>org.agoncal.sample.arquilian.wytiwyr.Book</class>
> > <properties>
> > <property
> > name="eclipselink.target-database" value="DERBY"/>
> > <property
> > name="eclipselink.ddl-generation"
> > value="create-tables"/>
> > <property
> > name="eclipselink.logging.level" value="INFO"/>
> > </properties>
> > </persistence-unit>
> > </persistence>
> >
> >
> > And my ItemEJB just injects the EntityManager :
> >
> >
> > @Stateless
> > @Path("/items")
> > public class ItemEJB {
> >
> >
> > @Inject
> > private EntityManager em;
> >
> >
> > public Book createBook(Book book) {
> > em.persist(book);
> > return book;
> > }
> > }
> >
> >
> > As I said, this works fine when deployed to
> > GlassFish, but not in embedded more
> > (using glassfish-embedded-all). I've seen several
> > JIRAs on this
> > (http://java.net/jira/browse/EMBEDDED_GLASSFISH-121, http://java.net/jira/browse/GLASSFISH-13672, http://java.net/jira/browse/GLASSFISH-15430) but because I use @DataSourceDefinition it's not related with any xml configuration
> >
> >
> > Any idea ?
> >
> >
> > Thanks,
> > Antonio
> >
> >
> > Stacktrace :
> >
> >
> > GRAVE: Exception while preparing the app
> > 5 janv. 2012 14:29:30
> > com.sun.enterprise.v3.server.ApplicationLifecycle
> > deploy
> > GRAVE: Invalid resource : { ResourceInfo :
> > (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }
> > java.lang.RuntimeException: Invalid resource :
> > { ResourceInfo :
> > (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }
> > at
> > com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:540)
> > at
> > com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:469)
> > at
> > org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
> > at
> > org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:154)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:119)
> > at org.glassfish.persistence.jpa.JPADeployer
> > $1.visitPUD(JPADeployer.java:214)
> > at org.glassfish.persistence.jpa.JPADeployer
> > $PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:483)
> > at
> > org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:221)
> > at
> > org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:167)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:872)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
> > at
> > org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $1.execute(CommandRunnerImpl.java:355)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.access
> > $1200(CommandRunnerImpl.java:96)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $ExecutionContext.execute(CommandRunnerImpl.java:1244)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $ExecutionContext.execute(CommandRunnerImpl.java:1232)
> > at
> > com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:147)
> > at
> > com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:99)
> > at
> > org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:142)
> > at
> > org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:134)
> > at
> > javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
> > at
> > org.agoncal.sample.arquilian.wytiwyr.ItemEJBWithoutArquillianIT.initContainer(ItemEJBWithoutArquillianIT.java:41)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at org.junit.runners.model.FrameworkMethod
> > $1.runReflectiveCall(FrameworkMethod.java:44)
> > at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> > at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> > at
> > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> > at
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> > at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:292)
> > at
> > org.junit.runner.JUnitCore.run(JUnitCore.java:157)
> > at
> > com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
> > at
> > com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
> > at
> > com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at
> > com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> > Caused by:
> > com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.validateResource(ConnectorResourceAdminServiceImpl.java:274)
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.setResourceInfo(ConnectorResourceAdminServiceImpl.java:255)
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl.lookupDataSourceInDAS(ConnectorResourceAdminServiceImpl.java:245)
> > at
> > com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:538)
> > ... 45 more
> > 5 janv. 2012 14:29:30
> > org.glassfish.deployment.admin.DeployCommand execute
> > GRAVE: Exception while preparing the app : Invalid
> > resource : { ResourceInfo :
> > (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }
> > com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.validateResource(ConnectorResourceAdminServiceImpl.java:274)
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.setResourceInfo(ConnectorResourceAdminServiceImpl.java:255)
> > at
> > com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl.lookupDataSourceInDAS(ConnectorResourceAdminServiceImpl.java:245)
> > at
> > com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:538)
> > at
> > com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:469)
> > at
> > org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
> > at
> > org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:154)
> > at
> > org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:119)
> > at org.glassfish.persistence.jpa.JPADeployer
> > $1.visitPUD(JPADeployer.java:214)
> > at org.glassfish.persistence.jpa.JPADeployer
> > $PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:483)
> > at
> > org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:221)
> > at
> > org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:167)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:872)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
> > at
> > com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
> > at
> > org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $1.execute(CommandRunnerImpl.java:355)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
> > at
> > com.sun.enterprise.v3.admin.CommandRunnerImpl.access
> > $1200(CommandRunnerImpl.java:96)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $ExecutionContext.execute(CommandRunnerImpl.java:1244)
> > at com.sun.enterprise.v3.admin.CommandRunnerImpl
> > $ExecutionContext.execute(CommandRunnerImpl.java:1232)
> > at
> > com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:147)
> > at
> > com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:99)
> > at
> > org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:142)
> > at
> > org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:134)
> > at
> > javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
> > at
> > org.agoncal.sample.arquilian.wytiwyr.ItemEJBWithoutArquillianIT.initContainer(ItemEJBWithoutArquillianIT.java:41)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at org.junit.runners.model.FrameworkMethod
> > $1.runReflectiveCall(FrameworkMethod.java:44)
> > at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> > at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> > at
> > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> > at
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> > at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:292)
> > at
> > org.junit.runner.JUnitCore.run(JUnitCore.java:157)
> > at
> > com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
> > at
> > com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
> > at
> > com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at
> > com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> > PlainTextActionReporterFAILUREDescription: deploy
> > AdminCommandError occurred during deployment:
> > Exception while preparing the app : Invalid
> > resource : { ResourceInfo :
> > (jndiName=java:app/jdbc/sampleArquilianWytiwyrDS__pm), (applicationName=classes) }. Please see server.log for more details.
> > [name=classes
> > 5 janv. 2012 14:29:30
> > org.glassfish.ejb.embedded.EJBContainerProviderImpl
> > createEJBContainer
> >
> >
> >
> >
> >
> >
> > --
> > --
> > Antonio Goncalves (antonio.goncalves_at_gmail.com)
> > Software architect
> >
> > Web site : www.antoniogoncalves.org
> > Blog: agoncal.wordpress.com
> > Feed: feeds2.feedburner.com/AntonioGoncalves
> > Paris JUG leader : www.parisjug.org
> > LinkedIn: www.linkedin.com/in/agoncal
> >
>
>
>
>
>
>
> --
> --
> Antonio Goncalves (antonio.goncalves_at_gmail.com)
> Software architect
>
> Web site : www.antoniogoncalves.org
> Blog: agoncal.wordpress.com
> Feed: feeds2.feedburner.com/AntonioGoncalves
> Paris JUG leader : www.parisjug.org
> LinkedIn: www.linkedin.com/in/agoncal
>