1 2 Previous Next 15 Replies Latest reply on Jan 19, 2011 8:23 AM by jaikiran pai

    JBossAS 6: Strange JNDI name for datasource

    Juergen Zimmermann Master

      So far my ear had a *-ds.xml file where I defined a datasource. The *-ds.xml file was declared as a service module in jboss-app.xml. In *-ds.xml the datasource was declared as follows:

      <datasources>

      <local-tx-datasource>

        <jndi-name>swe1DS</jndi-name>

       

      This datasource could be (re-) used in the EJB module's META-INF/persistence.xml as follows:

      <jta-data-source>java:/swe1DS</jta-data-source>

       

      Now, I used the new definition facility of JavaEE 6, and declared the datasource inside the EAR in META-INF/application.xml as follows:

      <data-source>

      <name>swe1DS</name>

       

      However, in META-INF/persistence I had to change the JNDI name as follows:

      <jta-data-source>java:internal/swe1/swe1/env/swe1DS</jta-data-source>

       

      Why is the EAR's name listed twice? Is this really intended or is this a bug?

        • 1. Re: JBossAS 6: Strange JNDI name for datasource
          jaikiran pai Master

          Don't use that internal JNDI name of the datasource. It's not meant to be used by applications.

           

          As for specifying a data-source in application.xml and then using it in persistence.xml, it's not going to work. The jta-data-source element of the persistence.xml is meant for:

           

           

          JPA2 spec, section 8.2.1.5 jta-data-source, non-jta-data-source

           

          In Java EE environments, the jta-data-source and non-jta-data-source elements are used to specify the global JNDI name of the JTA and/or non-JTA data source to be used by the persistence provider. If neither is specified, the deployer must specify a JTA data source at deployment or a JTA data source must be provided by the container, and a JTA EntityManagerFactory will be created to correspond to it.

           

          These elements name the data source in the local environment; the format of these names and the ability to specify the names are product specific.

           

           

           

           

           

          In JBoss AS, you can use only the jndi names that have been specified in a *-ds.xml file of the datasource.

          • 2. JBossAS 6: Strange JNDI name for datasource
            arjan tijms Novice

            This is really interesting. I hadn't noticed the new <data-source> element in application.xml yet.

             

            If it can't be used in persistence.xml, where can it be used then? Is there any effort (for Java EE 7 maybe) going on to make it possible to use such definition elsewhere and/or to standardize its JNDI name?

            • 3. JBossAS 6: Strange JNDI name for datasource
              jaikiran pai Master

              arjan tijms wrote:

               

              This is really interesting. I hadn't noticed the new <data-source> element in application.xml yet.

               

              If it can't be used in persistence.xml, where can it be used then?

              The spec allows you to use it as a resource-ref or a @Resource. Section EE.5.17 of JavaEE6 spec has the details.

              • 4. Re: JBossAS 6: Strange JNDI name for datasource
                henk de boer Master

                jaikiran pai wrote:

                 

                In JBoss AS, you can use only the jndi names that have been specified in a *-ds.xml file of the datasource.

                 

                Jaikiran, do you know if this was intentional or an oversight of the Java EE expert group? I thought the Java EE 6 specification was all about alining the different parts of Java EE. Why would the spec explicitly allow for two 'groups' of data source to be defined?

                 

                One group that is the universal one and is vendor specific, and one new group of data sources that can only be injected with @Resource but not used with JPA? Or can I use them with JPA after I define an additional resource-ref? (if this would be possible, it would be cool, but *requiring* it would contradict another Java EE 6 theme: easy of use).

                 

                The spec gives this as example for the data-source definition in application.xml:

                 

                 

                <data-source>
                     <description>Sample DataSource definition</description>
                     <name>java:app/MyDataSource</name>
                     <class-name>com.foobar.MyDataSource</class-name>
                     <server-name>myserver.com</server-name>
                     <port-number>6689</port-number>
                     <database-name>myDatabase</database-name>
                     <user>lance</user>
                     <password>secret</password>
                     <property>
                          <name>Property1</name>
                          <value>10</value>
                     </property>
                     <property>
                          <name>Property2</name>
                          <value>20</value>
                     </property>
                     <login-timeout>0</login-timeout>
                     <transactional>false</transactional>
                     <isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
                     <initial-pool-size>0</initial-pool-size>
                     <max-pool-size>30</max-pool-size>
                     <min-pool-size>20</min-pool-size>
                     <max-idle-time>0</max-idle-time>
                     <max-statements>50</max-statements>
                </data-source>
                

                 

                The javaee_6.xsd lists a few more elements, but something that I'm missing is how to specify that I would like an XA or non-XA datasource.

                 

                How does JBoss AS 6 threat a datasource definition such as this? Will it automatically be an XA datasource, or is a custom property required to indicate this?

                • 5. Re: JBossAS 6: Strange JNDI name for datasource
                  henk de boer Master

                  p.s.

                   

                  The spec also mentions this EE.5.17:

                   

                  The DataSource resource may be defined in any of the JNDI namespaces described in Section EE.5.2.2, “Application Component Environment Namespaces”.

                  For example,a DataSource resource may be defined:

                  • in the java:comp namespace, for use by a single component;

                  • in the java:module namespace, for use by all components in a module;

                  • in the java:app namespace, for use by all components in an application;

                  • in the java:global namespace, for use by all applications.

                   

                   

                  However, no matter which namespace I use for the definition, it always ends up in java:internal/[ear name]/[ear name]/[datasource name].

                   

                  Isn't that behavior violating the spec or am I missing something (or interpreting the spec wrongly)?

                  • 6. Re: JBossAS 6: Strange JNDI name for datasource
                    henk de boer Master

                    jaikiran pai wrote:

                     

                    The spec allows you to use it as a resource-ref or a @Resource. Section EE.5.17 of JavaEE6 spec has the details.

                     

                    This too does not seem to work. As JBoss AS creates this java:internal name and not the defined name, how do we know what to define in the @Resource annotation?

                     

                    I tried the following in application.xml:

                     

                    <data-source>
                        <description>Sample DataSource definition</description>
                        <name>java:app/MyDataSource</name>
                        <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
                        <server-name>myserver.com</server-name>
                        <port-number>5432</port-number>
                        <database-name>mydb</database-name>
                    
                        <user>myuser</user>
                        <password>mypass</password>  
                    </data-source>
                    
                    

                     

                    And the following code:

                     

                    package test;
                    
                    import javax.annotation.Resource;
                    import javax.ejb.Stateless;
                    import javax.sql.DataSource;
                    
                    @Stateless
                    public class MyBean {
                    
                      @Resource(lookup="java:app/MyDataSource")
                      DataSource myDB;
                    
                    }
                    
                    

                     

                     

                    But it fails with the following:

                     

                     

                    DEPLOYMENTS IN ERROR:
                      Deployment "java:app/MyDataSource" is in error due to the following reason(s): ** NOT FOUND Depends on 'java:app/MyDataSource' **
                      Deployment "<UNKNOWN jboss.j2ee:ear=eartest.ear,jar=eartestEJB.jar,name=MyBean,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-injector:bean=MyBean,topLevelUnit=eartest.ear,unit=eartestEJB.jar' **
                      Deployment "<UNKNOWN jboss-injector:topLevelUnit=eartest.ear,unit=eartestEJB.jar,bean=MyBean>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-switchboard:appName=eartest,module=eartestEJB,name=MyBean' **
                    
                    
                    

                     

                    The spec gives some code that suggest this should work:

                     

                    @Stateless public class MySessionBean {
                        @Resource(lookup = "java:app/MyDataSource") 
                        DataSource myDB;
                    
                    

                     

                    (a small tip btw for people wanting to try this in Eclipse/WTP: by default the JDK6's javax.annotation.Resource will be first on the build-path, and this one doesn't have the lookup attribute. You can change the order in project properties -> Java Build Path)

                     

                    I also tried with the mappedName attribute, but this gave the same error. Maybe this is not too surprising given that lookup suggest it's looks up the given JNDI location, but obviously there is nothing at java:app/MyDataSource.

                     

                    Any idea?

                    • 7. Re: JBossAS 6: Strange JNDI name for datasource
                      jaikiran pai Master

                      henk de boer wrote:

                       

                      However, no matter which namespace I use for the definition, it always ends up in java:internal/[ear name]/[ear name]/[datasource name].

                       

                       

                      Don't worry about the internal jndi name, we internally create a LinkRef to it. The applications are not supposed to use it.

                      • 8. Re: JBossAS 6: Strange JNDI name for datasource
                        jaikiran pai Master

                        henk de boer wrote:

                         

                        jaikiran pai wrote:

                         

                        The spec allows you to use it as a resource-ref or a @Resource. Section EE.5.17 of JavaEE6 spec has the details.

                         

                        This too does not seem to work. As JBoss AS creates this java:internal name and not the defined name, how do we know what to define in the @Resource annotation?

                         

                        I tried the following in application.xml:

                         

                        <data-source>
                            <description>Sample DataSource definition</description>
                            <name>java:app/MyDataSource</name>
                            <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
                            <server-name>myserver.com</server-name>
                            <port-number>5432</port-number>
                            <database-name>m4ndb</database-name>
                        
                            <user>myuser</user>
                            <password>mypass</password>  
                        </data-source>
                        
                        

                         

                        The spec also allows defining the datasource via ejb-jar.xml (or even web.xml). Can you try moving over this datasource definition in to ejb-jar.xml and then use it in the SLSB as  you currently do?

                        • 9. Re: JBossAS 6: Strange JNDI name for datasource
                          henk de boer Master

                          jaikiran pai wrote:

                          The spec also allows defining the datasource via ejb-jar.xml (or even web.xml). Can you try moving over this datasource definition in to ejb-jar.xml and then use it in the SLSB as  you currently do?

                          It seems like ejb-jar.xml is incapable of housing this element: http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd The data-source element does not appear in its xsd.

                           

                          web.xml does seem to be possible, but if I define the data-source the same kind of internal name is created:

                           

                           

                           

                          12:17:57,086 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=internal/eartest/eartestWeb/MyDataSource' to JNDI name 'java:internal/eartest/eartestWeb/MyDataSource'
                          
                          

                           

                          So this time it's java:internal/eartest/eartestWeb/MyDataSource, while I requested java:app/MyDataSource. So this one too doesn't work like expected I think.

                           

                          Additionally, I figured that if the web module would put the data-source at the right JNDI location AND the web module started before the EJB module, I could do the injection in my EJB.

                           

                          However, I stumbled upon another problem. It seems that the new <initialize-in-order> element in application.xml is not honored by JBoss AS 6. I tried the following:

                           

                           

                          <?xml version="1.0" encoding="UTF-8"?>
                          <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns="http://java.sun.com/xml/ns/javaee" 
                            xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
                            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
                            id="Application_ID" version="6">
                          
                            <display-name>eartest</display-name>
                          
                            <initialize-in-order>true</initialize-in-order>
                          
                            <module>
                              <web>
                                <web-uri>eartestWeb.war</web-uri>
                                <context-root>eartestWeb</context-root>
                              </web>
                            </module>
                          
                            <module>
                              <ejb>eartestEJB.jar</ejb>
                            </module>
                          
                          </application>
                          
                          

                           

                          But it seems to have no effect.

                          • 10. Re: JBossAS 6: Strange JNDI name for datasource
                            jaikiran pai Master

                            henk de boer wrote:

                             

                            jaikiran pai wrote:

                            The spec also allows defining the datasource via ejb-jar.xml (or even web.xml). Can you try moving over this datasource definition in to ejb-jar.xml and then use it in the SLSB as  you currently do?

                            It seems like ejb-jar.xml is incapable of housing this element: http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd The data-source element does not appear in its xsd.

                            It's there. It's part of the jndiEnvironmentRefsGroup which gets imported via javaee_6.xsd.

                             

                             

                            henk de boer wrote:

                             


                            web.xml does seem to be possible, but if I define the data-source the same kind of internal name is created:

                             

                             

                             

                            12:17:57,086 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=internal/eartest/eartestWeb/MyDataSource' to JNDI name 'java:internal/eartest/eartestWeb/MyDataSource'
                            
                            

                             

                            Like I have been saying all along, the internal name will be generated. Additionally the spec compliant name will also be generated (probably not logged).

                             

                             

                             

                             

                            henk de boer wrote:

                             


                             

                            Additionally, I figured that if the web module would put the data-source at the right JNDI location AND the web module started before the EJB module, I could do the injection in my EJB.

                            I'm not sure I understand what you meant with this one

                             

                             

                             

                            henk de boer wrote:

                             


                            However, I stumbled upon another problem. It seems that the new <initialize-in-order> element in application.xml is not honored by JBoss AS 6. I tried the following:

                             

                             

                            <?xml version="1.0" encoding="UTF-8"?>
                            <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xmlns="http://java.sun.com/xml/ns/javaee" 
                              xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
                              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
                              id="Application_ID" version="6">
                            
                              <display-name>eartest</display-name>
                            
                              <initialize-in-order>true</initialize-in-order>
                            
                              <module>
                                <web>
                                  <web-uri>eartestWeb.war</web-uri>
                                  <context-root>eartestWeb</context-root>
                                </web>
                              </module>
                            
                              <module>
                                <ejb>eartestEJB.jar</ejb>
                              </module>
                            
                            </application>
                            
                            

                             

                            But it seems to have no effect.

                             

                            Please create a new thread for that one. Let's see what the problem is.

                            • 11. Re: JBossAS 6: Strange JNDI name for datasource
                              henk de boer Master

                              Hi,

                              jaikiran pai wrote:

                              It's there. It's part of the jndiEnvironmentRefsGroup which gets imported via javaee_6.xsd.

                               

                              Okay, I'm afraid that's beyond my basic knowledge Could you explain this?

                               

                              I'm now using this ejb-jar.xml:

                               

                               

                              <?xml version="1.0" encoding="ASCII"?>
                              <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
                                xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
                                version="3.1">
                                <display-name>eartestEJB</display-name>
                              
                              </ejb-jar>
                              
                              

                               

                              Can I import the javaee_6.xsd here (and change the default namespace) and will this then work somehow? I'm a little confused here.

                               

                               

                              Like I have been saying all along, the internal name will be generated. Additionally the spec compliant name will also be generated (probably not logged).

                               

                              My initial guess was indeed that the spec compliant name just wasn't logged, but I checked the JNDI tree and it simply wasn't there. The resource with the lookup that specified the spec compliant name also failed. I guess I could try a direct JNDI lookup in bean code, but till so far it really doesn't seem to be there.

                               

                              This is the JNDI tree after the EAR with the datasource definition in application.xml was deployed:

                               

                               

                              <h1> Other components with java:comp namespace</h1>
                              <h1>java: Namespace</h1>
                              <pre>
                                +- securityManagement (class: org.jboss.security.integration.JNDIBasedSecurityManagement)
                                +- comp (class: javax.naming.Context)
                                +- XAConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                                +- JmsXA (class: org.hornetq.ra.HornetQRAConnectionFactoryImpl)
                                +- policyRegistration (class: org.jboss.security.plugins.JBossPolicyRegistration)
                                +- TransactionPropagationContextImporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
                                +- app (class: javax.naming.Context)
                              Failed to lookup: app, errmsg=java:app not supported by legacy component null
                                +- Mail (class: javax.mail.Session)
                                +- TransactionPropagationContextExporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
                                +- ProfileService (class: org.jboss.profileservice.AbstractProfileService)
                                +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                                +- jaas (class: javax.naming.Context)
                                |   +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
                                |   +- hornetq (class: org.jboss.security.plugins.SecurityDomainContext)
                                +- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)
                                +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
                                +- ConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                                +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
                                +- TransactionManager (class: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate)
                                +- timedCacheFactory (class: javax.naming.Context)
                              Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy cannot be cast to javax.naming.NamingEnumeration
                                +- module (class: javax.naming.Context)
                              Failed to lookup: module, errmsg=java:module not supported by legacy component null
                                +- internal (class: org.jnp.interfaces.NamingContext)
                                |   +- eartest (class: org.jnp.interfaces.NamingContext)
                                |   |   +- eartest (class: org.jnp.interfaces.NamingContext)
                                |   |   |   +- MyDataSource (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                                |   |   |   +- env (class: org.jnp.interfaces.NamingContext)
                                |   +- EJBContext (class: javax.ejb.EJBContext)
                                |   +- TimerService (class: javax.ejb.TimerService)
                                +- global (class: org.jnp.interfaces.NamingContext)
                                |   +- eartest (class: org.jnp.interfaces.NamingContext)
                                |   |   +- eartestWeb (class: org.jnp.interfaces.NamingContext)
                                |   +- ROOT (class: org.jnp.interfaces.NamingContext)
                                |   +- uuid-key-generator (class: org.jnp.interfaces.NamingContext)
                                |   +- http-invoker (class: org.jnp.interfaces.NamingContext)
                                |   |   +- invoker (class: org.jnp.interfaces.NamingContext)
                                |   +- cdi (class: org.jnp.interfaces.NamingContext)
                              </pre>
                              <h1>Global JNDI Namespace</h1>
                              <pre>
                                +- UserTransactionSessionFactory (proxy: $Proxy105 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
                                +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
                                +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
                                +- SecureDeploymentManager (class: org.jnp.interfaces.NamingContext)
                                |   +- remote[link -> DeploymentManager] (class: javax.naming.LinkRef)
                                +- SecureManagementView (class: org.jnp.interfaces.NamingContext)
                                |   +- remote[link -> ManagementView] (class: javax.naming.LinkRef)
                                +- DeploymentManager (class: org.jboss.aop.generatedproxies.AOPProxy$4)
                                +- XAConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                                +- ProfileService (class: org.jboss.aop.generatedproxies.AOPProxy$2)
                                +- persistence.unit:unitName=eartest.ear (class: org.jnp.interfaces.NamingContext)
                                |   +- eartestEJB.jar#eartestEJB (class: org.hibernate.impl.SessionFactoryImpl)
                                +- SecureProfileService (class: org.jnp.interfaces.NamingContext)
                                |   +- remote[link -> ProfileService] (class: javax.naming.LinkRef)
                                +- queue (class: org.jnp.interfaces.NamingContext)
                                |   +- DLQ (class: org.hornetq.jms.client.HornetQQueue)
                                |   +- ExpiryQueue (class: org.hornetq.jms.client.HornetQQueue)
                                +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
                                +- ConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                                +- jmx (class: org.jnp.interfaces.NamingContext)
                                |   +- invoker (class: org.jnp.interfaces.NamingContext)
                                |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
                                |   +- rmi (class: org.jnp.interfaces.NamingContext)
                                |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
                                +- BeanValidatorFactories (class: org.jnp.interfaces.NamingContext)
                                +- TomcatAuthenticators (class: java.util.Properties)
                                +- XAThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                                +- ManagementView (class: org.jboss.aop.generatedproxies.AOPProxy$3)
                                +- ThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
                              </pre>
                              
                              

                               

                               

                               

                               

                               

                              henk de boer wrote:

                               


                               

                              Additionally, I figured that if the web module would put the data-source at the right JNDI location AND the web module started before the EJB module, I could do the injection in my EJB.

                              I'm not sure I understand what you meant with this one

                               

                              The idea was that if I define the datasource in web.xml, then after the web module was deployed/initialized the datasource would correctly be inserted in JNDI at java:app/MyDataSource. Then after the web module, the ejb module would be deployed/initialized. In the EJB module I have a session bean with the @Resource(lookup="java:app/MyDataSource") annotation.

                               

                              If java:app/MyDataSource would be available, this this @Resource based injection would succeed.

                               

                              For this to work, you would say the web module has to deployed/initialized before the EJB module.

                               

                               

                              jaikiran pai wrote:

                              Please create a new thread for that one. Let's see what the problem is.

                               

                              Okay, I will.

                              • 12. Re: JBossAS 6: Strange JNDI name for datasource
                                jaikiran pai Master

                                henk de boer wrote:

                                 

                                Hi,

                                jaikiran pai wrote:

                                It's there. It's part of the jndiEnvironmentRefsGroup which gets imported via javaee_6.xsd.

                                 

                                Okay, I'm afraid that's beyond my basic knowledge Could you explain this?

                                 

                                I'm now using this ejb-jar.xml:

                                 

                                 

                                <?xml version="1.0" encoding="ASCII"?><ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
                                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
                                  version="3.1">  <display-name>eartestEJB</display-name>
                                </ejb-jar>
                                

                                 

                                Can I import the javaee_6.xsd here (and change the default namespace) and will this then work somehow? I'm a little confused here.

                                The ejb-jar_3_1.xsd internally imports the javaee_6.xsd. What this means is some of the elements and groups defined in javaee_6.xsd are usable within the ejb-jar.xml. Here's a pseudo code:

                                 

                                <?xml version="1.0" encoding="UTF-8"?>
                                <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  version="3.1" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
                                  <enterprise-beans>
                                    <session>
                                      <ejb-name>TestBean</ejb-name>
                                      <data-source>
                                        <description>java:app/TestDS</description>
                                        <name>java:app/TestDS</name>
                                ...
                                      </data-source>
                                    </session>
                                  </enterprise-beans>
                                </ejb-jar>
                                

                                 

                                 

                                 

                                henk de boer wrote:

                                 


                                 

                                Like I have been saying all along, the internal name will be generated. Additionally the spec compliant name will also be generated (probably not logged).

                                 

                                My initial guess was indeed that the spec compliant name just wasn't logged, but I checked the JNDI tree and it simply wasn't there. The resource with the lookup that specified the spec compliant name also failed. I guess I could try a direct JNDI lookup in bean code, but till so far it really doesn't seem to be there.

                                 

                                This is the JNDI tree after the EAR with the datasource definition in application.xml was deployed:

                                 

                                Don't use the application.xml for the data-source for now. It's a bug that it isn't working in that descriptor. I'll file a JIRA later tonight or you can do the honours Try it with ejb-jar.xml, like the example I posted.

                                 

                                 

                                henk de boer wrote:

                                 


                                 

                                 

                                henk de boer wrote:

                                 


                                 

                                Additionally, I figured that if the web module would put the data-source at the right JNDI location AND the web module started before the EJB module, I could do the injection in my EJB.

                                I'm not sure I understand what you meant with this one

                                 

                                The idea was that if I define the datasource in web.xml, then after the web module was deployed/initialized the datasource would correctly be inserted in JNDI at java:app/MyDataSource. Then after the web module, the ejb module would be deployed/initialized. In the EJB module I have a session bean with the @Resource(lookup="java:app/MyDataSource") annotation.

                                 

                                If java:app/MyDataSource would be available, this this @Resource based injection would succeed.

                                 

                                For this to work, you would say the web module has to deployed/initialized before the EJB module.

                                Are those 2 part of the same .ear? If yes, then it's expected to work.

                                • 13. Re: JBossAS 6: Strange JNDI name for datasource
                                  henk de boer Master

                                  jaikiran pai wrote:

                                   

                                  The ejb-jar_3_1.xsd internally imports the javaee_6.xsd. What this means is some of the elements and groups defined in javaee_6.xsd are usable within the ejb-jar.xml. Here's a pseudo code:

                                   

                                  <?xml version="1.0" encoding="UTF-8"?><ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                    version="3.1" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">  <enterprise-beans>    <session>      <ejb-name>TestBean</ejb-name>      <data-source>        <description>java:app/TestDS</description>        <name>java:app/TestDS</name>...
                                        </data-source>    </session>  </enterprise-beans></ejb-jar>

                                   

                                   

                                  I see. That's something really... I guess this is more or less the XML equivalent of using the @DataSourceDefinition annotation on an EJB bean (or other managed class). Although this is not exactly what I wanted I'll try it out. Thanks!

                                   

                                  Don't use the application.xml for the data-source for now. It's a bug that it isn't working in that descriptor. I'll file a JIRA later tonight or you can do the honours

                                  Oh well, it doesn't really matter, but I'll take the honours then

                                   

                                   

                                  Are those 2 part of the same .ear? If yes, then it's expected to work.

                                   

                                  Yes, they are part of the same ear. It doesn't work when I used the name I asked for (java:app/TestDS), but if I use the internal name it indeed does work. In the latter case I didn't try the injection in an EJB, but the JTA datasource in a persistence.xml in the EJB module.

                                   

                                  There is on other odd thing here.

                                   

                                  From the logs it seems that the EJB module is always initialized before the Web module, but the data source I defined in web.xml is available for the persistence unit in the EJB module (using the internal name). How can this be? Are the modules initialized in two phases or so?

                                  1 2 Previous Next