Skip to main content

@DataSourceDefinition and EJBContainer?

7 replies [Last post]
ljnelson
Offline
Joined: 2003-08-04

I'm not seeing that javax.annotation.sql.DataSourceDefinition is working when I do EJBContainer#createEJBContainer().

I've placed this annotation on my (now, finally) discovered EJB (which otherwise loads fine). It looks like this:

<br />
@javax.annotation.sql.DataSourceDefinition(<br />
  name = "java:global/env/H2Test",<br />
  url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",<br />
  className = "org.h2.Driver",<br />
  user = "sa",<br />
  password = ""<br />
)<br />
@Stateless<br />
public class FooBean implements Foo {<br />
  //...<br />
}<br />

And my persistence.xml refers to it like this:

<br />
<?xml version="1.0" encoding="UTF-8"?></p>
<p>    java:global/env/H2Test</p>
<p>

(Obviously I have much to add here; I'm just trying to see if this might be a way to define a data source quickly and easily in embedded testing. So far no luck.)

The container bombs out with a NamingException saying that "env", actually, can't be found:

<br />
Caused by: javax.naming.NameNotFoundException: env<br />
	at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252)<br />
	at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171)<br />
	at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172)<br />
	at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)<br />
	at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:101)<br />
	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)<br />

To be clear, I'm running this in "unsanctioned" mode :-). I don't have a preexisting Glassfish installation; I'm relying on a transitive Maven download of org.glassfish.extras:glassfish-embedded-all:3.0.1-b02.

Is this a known problem?

Best,
Laird

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ljnelson
Offline
Joined: 2003-08-04
mvatkina
Offline
Joined: 2005-04-04

It does work in a non-embedded case for java:global/env prefix used in both, the definition and the persistence.xml value for the .

Laird, please file a bug for the embedded case - it fails with the same exception when ran against a pre-existing install with the -shell.jar.

thanks,
-marina

mvatkina
Offline
Joined: 2005-04-04

It doesn't fully work in a non-embedded case either. Only the 1st deploy after server restart is somehow working. Neither undeploy, not subsequent deploy can see the resource defined via @DataSourceDefinition.

Regards,
-marina

Sahoo

I see a potential ordering issue here: the datasource has to be created
before persistence unit that uses it is loaded. Does it work in
non-embedded case?

Thanks,
Sahoo
glassfish@javadesktop.org wrote:
> I'm not seeing that javax.annotation.sql.DataSourceDefinition is working when I do EJBContainer#createEJBContainer().
>
> I've placed this annotation on my (now, finally) discovered EJB (which otherwise loads fine). It looks like this:
>
> [code]
> @javax.annotation.sql.DataSourceDefinition(
> name = "java:global/env/H2Test",
> url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
> className = "org.h2.Driver",
> user = "sa",
> password = ""
> )
> @Stateless
> public class FooBean implements Foo {
> //...
> }
> [/code]
>
> And my persistence.xml refers to it like this:
>
> [code]
>
>
>
>
> java:global/env/H2Test
>
>
>
> [/code]
>
> (Obviously I have much to add here; I'm just trying to see if this might be a way to define a data source quickly and easily in embedded testing. So far no luck.)
>
> The container bombs out with a NamingException saying that "env", actually, can't be found:
>
> [code]
> Caused by: javax.naming.NameNotFoundException: env
> at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252)
> at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171)
> at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172)
> at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)
> at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:101)
> at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
> [/code]
>
> To be clear, I'm running this in "unsanctioned" mode :-). I don't have a preexisting Glassfish installation; I'm relying on a transitive Maven download of org.glassfish.extras:glassfish-embedded-all:3.0.1-b02.
>
> Is this a known problem?
>
> Best,
> Laird
> [Message sent by forum member 'ljnelson']
>
> http://forums.java.net/jive/thread.jspa?messageID=396015
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

ljnelson
Offline
Joined: 2003-08-04

> I see a potential ordering issue here: the datasource
> has to be created
> before persistence unit that uses it is loaded. Does
> it work in
> non-embedded case?

Huh; I don't know. Have to say I was just following simple instructions :-) that said I could put a @DataSourceDefinition on an EJB class. It seemed like a really quick and dirty and easy way to set up H2 for an embedded unit test.

I think the spec doesn't prohibit this (EE 5.17).

Best,
Laird

Huiping Zhang

Hi,

When one web application is set 2 context-root in application.xml in ear file, deployment will fail in sgcs. Is it expected?

Here is the content of one example of application.xml


my appliaction
test


my.war
/root1




my.war
/root2


Part of stack trace is

[#|2010-04-09T10:15:07.824-0400|SEVERE|sun-glassfish-comms-server2.0|javax.enterprise.system.tools.deployment|_ThreadID=50;_ThreadNameead-900;_RequestID=768e739d-0cd0-4e4f-a10e-0b55ff375381;|Could not expand entry null into destination /cluster/home/mmas/nodes/DAS/dom/domain1/applications/j2ee-apps/...
java.io.IOException: Error expanding archive /cluster/home/mmas/nodes/DAS/domains/domain1/applications/j2ee-apps/....; please see the server log file for more information
at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeJar(J2EEModuleExploder.java:359)
at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeEar(J2EEModuleExploder.java:296)
at com.sun.enterprise.deployment.backend.AppDeployer.explodeArchive(AppDeployer.java:294)
at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:207)
at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:148)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:208)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:966)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:283)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:835)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:225)
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:114)
at java.util.jar.JarFile.(JarFile.java:133)
at java.util.jar.JarFile.(JarFile.java:97)
at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeJar(J2EEModuleExploder.java:311)
... 11 more

Thanks in advance for any information,
Huiping
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Hong Zhang

You can only define each module one time in the application.xml (of
course, glassfish should probably give a better error message here).

On 4/9/2010 10:28 AM, Huiping Zhang wrote:
> Hi,
>
> When one web application is set 2 context-root in application.xml in ear file, deployment will fail in sgcs. Is it expected?
>
> Here is the content of one example of application.xml
>
>
> my appliaction
> test
>
>
> my.war
> /root1
>

>

>
>
> my.war
> /root2
>

>

>

>
>
> Part of stack trace is
>
>
> [#|2010-04-09T10:15:07.824-0400|SEVERE|sun-glassfish-comms-server2.0|javax.enterprise.system.tools.deployment|_ThreadID=50;_ThreadNameead-900;_RequestID=768e739d-0cd0-4e4f-a10e-0b55ff375381;|Could not expand entry null into destination /cluster/home/mmas/nodes/DAS/dom/domain1/applications/j2ee-apps/...
> java.io.IOException: Error expanding archive /cluster/home/mmas/nodes/DAS/domains/domain1/applications/j2ee-apps/....; please see the server log file for more information
> at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeJar(J2EEModuleExploder.java:359)
> at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeEar(J2EEModuleExploder.java:296)
> at com.sun.enterprise.deployment.backend.AppDeployer.explodeArchive(AppDeployer.java:294)
> at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:207)
> at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:148)
> at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:208)
> at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
> at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:966)
> at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:283)
> at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:835)
> at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
> at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:225)
> Caused by: java.util.zip.ZipException: error in opening zip file
> at java.util.zip.ZipFile.open(Native Method)
> at java.util.zip.ZipFile.(ZipFile.java:114)
> at java.util.jar.JarFile.(JarFile.java:133)
> at java.util.jar.JarFile.(JarFile.java:97)
> at com.sun.enterprise.deployment.backend.J2EEModuleExploder.explodeJar(J2EEModuleExploder.java:311)
> ... 11 more
>
> Thanks in advance for any information,
> Huiping
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net