1 2 3 Previous Next 30 Replies Latest reply on Dec 20, 2011 2:09 PM by henk53 Go to original post
      • 15. Re: datasource.xml needed?
        jaikiran

        nimo stephan wrote:


        The fact is:

         

        When using JBOSS AS and when I want to use connection pooling, then I have to use a datasource even if I declared the SAME datas (connection-url, driver-class, user-name, password) already in a standardized JPA2-manner.

        I think you missed my point in one of my previous replies. The JPA spec doesn't say anything about pooling. Also, if you use the datasource, you don't need those properties in the persistence.xml. The JPA spec says this:

         

         

        The following properties defined by this specification are intended for use in Java SE environments.

         

             - javax.persistence.jdbc.driver — fully qualified name of the driver class

             - javax.persistence.jdbc.url — driver-specific URL

             - javax.persistence.jdbc.user — username used by database connection

             - javax.persistence.jdbc.password — password for database connection validation

         

        So it's not the "same" properties.

         

        nimo stephan wrote:

         


         

        By the way, I guess, the xy-ds.xml is not standard-conform because we have to use the doctype "//JBoss//DTD JBOSS JCA Config 1.5//EN", hence  xy-ds.xml cannot be used in other JEE-Containers -xy-ds.xml ispure jboss-specific.

        Yes, it's JBoss specific, which I mentioned already in many previous replies.

         

         

        nimo stephan wrote:

         


         

        The question is:

         

        Would it be senseful, if Jboss AS takes the values needed for connection pooling out of the persistence.xml. If so, then we can deprecate xy-ds.xml;)

         

        Like I said a few lines above, it's not the same info. Also, remember that *-ds.xml datasources can be used in applications which do not use JPA. So deprecating them isn't a good idea.

        • 16. Re: datasource.xml needed?
          nimo22

          I was confused about these java-se properties. But now, it is clear, thank you !!

          • 17. Re: datasource.xml needed?
            nimo22

            Sorry Nicklas, I have overlooked your message about @DataSourceDefinition. That is exactly what I want, so I tried it:

             

            My ApplicationScoped Bean:

             

            @ApplicationScoped

            @DataSourceDefinitions({

                  @DataSourceDefinition(

                          name = "java:app/ds_test",

                          className = "com.ibm.db2.jcc.DB2Driver",

                          portNumber = 50000,

                          serverName = "localhost",

                          databaseName = "test",

                          user = "xy",

                          password = "xy")

                })

            public class Application {

             

            ...

            }

             

            My persistence.xml:

             

            <?xml version="1.0" encoding="UTF-8"?>

            <persistence version="2.0"

               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">

             

               <persistence-unit name="pu_test">

                  <provider>org.hibernate.ejb.HibernatePersistence</provider>

                  <jta-data-source>java:app/ds_test</jta-data-source>

            ...

            </persistence-unit>

            </persistence>

             

            And unfortunately, my stacktrace:

             

            09:54:44,009 INFO  [AbstractServer] Starting: JBossAS [6.1.0.SNAPSHOT "Neo"]

            09:54:45,494 INFO  [ServerInfo] Java version: 1.6.0_21,Sun Microsystems Inc.

            09:54:45,494 INFO  [ServerInfo] Java Runtime: Java(TM) SE Runtime Environment (build 1.6.0_21-b06)

            09:54:45,494 INFO  [ServerInfo] Java VM: Java HotSpot(TM) Client VM 17.0-b16,Sun Microsystems Inc.

            ...

            09:55:37,588 INFO  [Version] WELD-000900 1.1.0 (Final)

            09:55:37,650 INFO  [service] Removing bootstrap log handlers

            09:55:38,181 INFO  [Version] Seam Solder 3.0.0.Beta1 (build id: 20101220-2046)

            09:55:39,197 ERROR [ProfileServiceBootstrap] Failed to load profile:: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

             

            DEPLOYMENTS MISSING DEPENDENCIES:

             

            Deployment "jboss-injector:appName=testwar,module=testwar" is missing the following dependencies:

            Dependency "<UNKNOWN jboss-injector:appName=testwar,module=testwar>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=testwar,module=testwar' **")

             

            Deployment "jboss-switchboard:appName=testwar,module=testwar" is missing the following dependencies:

            Dependency "persistence.unit:unitName=testwar.war#pu_test" (should be in state "Installed", but is actually in state "Configured")

            Deployment "jboss.web.deployment:war=/testwar" is missing the following dependencies:

            Dependency "jboss-injector:appName=testwar,module=testwar" (should be in state "Create", but is actually in state "Configured")

            Deployment "persistence.unit:unitName=testwar.war#pu_test" is missing the following dependencies:

            Dependency "jboss.jca:name=app/ds_test,service=DataSourceBinding" (should be in state "Create", but is actually in state "** NOT FOUND Depends on 'jboss.jca:name=app/ds_test,service=DataSourceBinding' **")


            DEPLOYMENTS IN ERROR:

             

            Deployment "jboss.jca:name=app/ds_test,service=DataSourceBinding" is in error due to the following reason(s): ** NOT FOUND Depends on 'jboss.jca:name=app/ds_test,service=DataSourceBinding' **

            Deployment "<UNKNOWN jboss-injector:appName=testwar,module=testwar>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-switchboard:appName=testwar,module=testwar' **


                at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.GA]

                at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.GA]

                at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.1.0-SNAPSHOT]

                at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]

                at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:135) [:6.1.0-SNAPSHOT]

                at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.1.0-SNAPSHOT]

                at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                at java.lang.Thread.run(Thread.java:619) [:1.6.0_21]

             

            09:55:39,213 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-LOCALHOST%2F127.0.0.1-8080

            09:55:39,228 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-LOCALHOST%2F127.0.0.1-8009

            09:55:39,228 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.1.0.SNAPSHOT "Neo"] Started in 55s:219ms

             

            What is wrong?

            ds_test
            • 18. Re: datasource.xml needed?
              nickarls

              Strange. How you tried with the global scope for the DS. Or just using a single @DataSourceDefinition?

              • 19. Re: datasource.xml needed?
                nickarls

                This works for me:

                @DataSourceDefinition(

                name = "java:app/env/inventory",

                className = "oracle.jdbc.pool.OracleDataSource",

                portNumber = 1521,

                serverName = "db",

                databaseName = "sid,

                user = "u",

                password = "p",

                properties = { "driverType=thin" })

                @Stateless

                @Named

                public class InventoryBean

                {

                   @Resource(mappedName = "java:app/env/inventory")

                   private DataSource inventoryds;

                 

                 

                   public String getInfo()

                   {

                      return String.format("DataSource is %s", inventoryds.toString());

                   }

                }

                 

                 

                 

                Calling #{inventoryBean.info} shows the class

                • 20. Re: datasource.xml needed?
                  jaikiran

                  Your "Application" class isn't really a EJB or a web app component (like servlet, filter etc...). So the @DataSourceDefinition will not be picked up from that class. As Nicklas showed in his example, you can use it on a EJB to get it working.

                  • 21. Re: datasource.xml needed?
                    jaikiran

                    And yes, you might want to bind it to java:global namespace, since the jta-data-source element in persistence.xml won't work out well with other namespaces http://community.jboss.org/message/580970#580970

                    • 22. Re: datasource.xml needed?
                      nimo22

                      This is my EJB:

                       

                      @Stateless

                      @DataSourceDefinition(

                      name = "java:app/env/ds_test",

                      className = "com.ibm.db2.jcc.DB2Driver",

                      portNumber = 50000,

                      serverName = "localhost",

                      databaseName = "mywar",

                      user = "xy",

                      password = "xy")

                      public class Application

                      {

                      ..

                       

                      }

                       

                       

                      The reference in my persistence.xml:

                      <persistence-unit name="pu_test">

                      ..

                      <jta-data-source>java:app/env/ds_test </jta-data-source>

                      ..

                      </persistence-unit>

                       

                       

                      I get the same stacktrace:

                       

                      11:19:48,271 WARN  [InterceptorInfoRepository] EJBTHREE-1852: InterceptorInfoRepository is deprecated

                      11:19:50,599 INFO  [JBossASKernel] Created KernelDeployment for: mywar.war

                      11:19:50,599 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=mywar.war,name=Application,service=EJB3

                      11:19:50,599 INFO  [JBossASKernel]   with dependencies:

                      11:19:50,599 INFO  [JBossASKernel]   and demands:

                      11:19:50,599 INFO  [JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described

                      11:19:50,599 INFO  [JBossASKernel]     jboss-switchboard:appName=mywar,module=mywar; Required: Create

                      11:19:50,599 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor; Required: Described

                      11:19:50,599 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor; Required: Described

                      11:19:50,599 INFO  [JBossASKernel]   and supplies:

                      11:19:50,599 INFO  [JBossASKernel]     jndi:Application

                      11:19:50,614 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=mywar.war,name=Application,service=EJB3) to KernelDeployment of: mywar.war

                      11:20:14,223 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=internal/mywar/mywar/Application/env/ds_test' to JNDI name 'java:internal/mywar/mywar/Application/env/ds_test'

                      11:20:14,426 INFO  [Version] WELD-000900 1.1.0 (Final)

                      11:20:14,489 INFO  [service] Removing bootstrap log handlers

                      11:20:15,083 INFO  [Version] Seam Solder 3.0.0.Beta1 (build id: 20101220-2046)

                      11:20:15,489 ERROR [ProfileServiceBootstrap] Failed to load profile:: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

                       

                      DEPLOYMENTS MISSING DEPENDENCIES:

                        Deployment "jboss-injector:appName=mywar,module=mywar" is missing the following dependencies:

                          Dependency "<UNKNOWN jboss-injector:appName=mywar,module=mywar>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **")

                        Deployment "jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor" is missing the following dependencies:

                          Dependency "<UNKNOWN jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **")

                        Deployment "jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor" is missing the following dependencies:

                          Dependency "<UNKNOWN jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **")

                        Deployment "jboss-switchboard:appName=mywar,module=mywar" is missing the following dependencies:

                          Dependency "persistence.unit:unitName=mywar.war#pu_test" (should be in state "Installed", but is actually in state "Configured")

                        Deployment "jboss.j2ee:jar=mywar.war,name=Application,service=EJB3" is missing the following dependencies:

                          Dependency "<UNKNOWN jboss.j2ee:jar=mywar.war,name=Application,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-injector:bean=Application,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor,topLevelUnit=mywar.war,unit=mywar.war' **")

                          Dependency "<UNKNOWN jboss.j2ee:jar=mywar.war,name=Application,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-injector:bean=Application,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor,topLevelUnit=mywar.war,unit=mywar.war' **")

                        Deployment "jboss.j2ee:jar=mywar.war,name=Application,service=EJB3,type=nointerface-view-jndi-binder" is missing the following dependencies:

                          Dependency "jboss.j2ee:jar=mywar.war,name=Application,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

                        Deployment "jboss.j2ee:jar=mywar.war,name=Application,service=EJB3_endpoint" is missing the following dependencies:

                          Dependency "jboss.j2ee:jar=mywar.war,name=Application,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

                        Deployment "jboss.web.deployment:war=/mywar" is missing the following dependencies:

                          Dependency "jboss-injector:appName=mywar,module=mywar" (should be in state "Create", but is actually in state "Configured")

                        Deployment "persistence.unit:unitName=mywar.war#pu_test" is missing the following dependencies:

                          Dependency "jboss.jca:name=app/env/ds_test,service=DataSourceBinding" (should be in state "Create", but is actually in state "** NOT FOUND Depends on 'jboss.jca:name=app/env/ds_test,service=DataSourceBinding' **")

                       

                      DEPLOYMENTS IN ERROR:

                        Deployment "<UNKNOWN jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **

                        Deployment "<UNKNOWN jboss-injector:topLevelUnit=mywar.war,unit=mywar.war,bean=Application,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **

                        Deployment "<UNKNOWN jboss-injector:appName=mywar,module=mywar>" is in error due to the following reason(s): ** UNRESOLVED Demands 'jboss-switchboard:appName=mywar,module=mywar' **

                        Deployment "jboss.jca:name=app/env/ds_test,service=DataSourceBinding" is in error due to the following reason(s): ** NOT FOUND Depends on 'jboss.jca:name=app/env/ds_test,service=DataSourceBinding' **

                       

                          at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.GA]

                          at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.GA]

                          at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.1.0-SNAPSHOT]

                          at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]

                          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:135) [:6.1.0-SNAPSHOT]

                          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.1.0-SNAPSHOT]

                          at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                          at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                          at java.lang.Thread.run(Thread.java:619) [:1.6.0_21]

                       

                      11:20:15,520 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-LOCALHOST%2F127.0.0.1-8080

                      11:20:15,520 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-LOCALHOST%2F127.0.0.1-8009

                      11:20:15,520 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.1.0.SNAPSHOT "Neo"] Started in 1m:4s:264ms

                       

                      What is wrong?

                      • 23. datasource.xml needed?
                        nickarls

                        Try the global namespace like Jaikiran suggested.

                        • 24. Re: datasource.xml needed?
                          nimo22

                          Okay, I will try it with java:global namespace and report.

                          • 25. datasource.xml needed?
                            juergen.zimmermann

                            Be careful about using @DataSourceDefinition. When you need security and you want to store usernames and roles in e.g. a database table, then your login module (for security config) needs the JNDI name of the datasource. I'm not sure if the JNDI name will already be available if it is provided by @DataSourceDefinition.

                            • 26. Re: datasource.xml needed?
                              nimo22

                              Unfortunately, I get always the same stacktrace.

                               

                              I have tried it with java:global/env/ds_test  instead of   java:app/env/ds_test - it is not working - the same stacktrace occurs.

                               

                              (I have also tried to use @Startup with @Singleton Annotation - I have thought, that maybe the persistence.xml is loaded before the datasource can be created, but I was wrong.)

                               

                              My Project is nothing special- I have only one EJB called Application.java.

                               

                              I used this archetype to create my webapp skeleton:

                               

                              Group Id: org.jboss.weld.archetypes

                              Artifact Id: jboss-javaee6-webapp

                              Version: 1.0.1.Beta1

                               

                              I dont know, if this is the reason.

                              • 27. Re: datasource.xml needed?
                                jaikiran

                                Okay, i'll take a look at this later today/tomorrow. If you have a simple application, please attach it here.

                                • 28. Re: datasource.xml needed?
                                  nimo22

                                  Here is the maven-project created by artifact jboss-javaee6-webapp:

                                   

                                  These are the changes are made:

                                  - I created a new folder called ejb with Application.java which includes the @DataSourceDefinition

                                  - I changed the persistence-unit

                                   

                                  By the way:

                                  Though it is a JEE6-Project, the new "lookup"-property of @Resource cannot be found as this archetype did not include the javaee-endorsed-api into its pom.

                                  (http://javahowto.blogspot.com/2010/04/resourcelookup-and-classpath.html)

                                   

                                  So use this:

                                  @Resource(mappedName = "java:global/testdb")

                                  private DataSource ds

                                   

                                  instead of this:

                                  @Resource(lookup="java:app/testdb")

                                  private DataSource ds

                                   

                                  I am using jboss 6.1 snapshot.

                                  • 29. Re: datasource.xml needed?
                                    henk53

                                    Just wondering, was this ever resolved?

                                     

                                    I'm also wondering why in this thread the consensus seemed to be that the data source could be used in persistence.xml, while here it was said that it could not be used:

                                     

                                    As for specifying a data-source in application.xml and then using it in persistence.xml, it's not going to work.