13 Replies Latest reply: May 28, 2014 10:34 AM by jaikiran pai RSS

    Default Datasource for entity beans

    Halli Balli Newbie

      Hallo everybody,

       

      maybe this is some stupid question. But I just don't find a solution. I am stuck for 3 days now.

       

      I have a project that uses ejb 2.1 definitions.

      I can deploy and remotly access my session beans, I have defined a datasource in standalone-full.xml.

       

       

      <subsystem xmlns="urn:jboss:domain:datasources:1.0">
           <datasources>
                <datasource jndi-name="java:jboss/datasources/DataSource" pool-name="DefaultDSPool" enabled="true" use-java-context="true">
                     <connection-url>jdbc:sqlserver://localhost:1433;DatabaseName=databasename</connection-url>
                     <driver>sqljdbc</driver>
                     <security>
                          <user-name>user</user-name>
                          <password>password</password>
                     </security>
                </datasource>
                <drivers>
                     <driver name="sqljdbc" module="com.microsoft.sqlserver.jdbc">
                          <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                     </driver>
                </drivers>
           </datasources>
      </subsystem>  
      

       

       

      I added the driver to the modules with the corresponding modules.xml

       

       

      I want to use Container Managed Persistence

       

      But when I try to deploy my application on the JBoss AS 7.1.0 final  I get the following errors:

       

       

      15:39:30,277 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015951: Admin console listening on http://127.0.0.1:9990
      15:39:30,281 ERROR [org.jboss.as] (MSC service thread 1-2) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors)
      in 56593ms - Started 4258 of 4967 services (596 services failed or missing dependencies, 112 services are passive or on-demand)
      15:39:30,492 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "applica.ear" was rol
      led back with failure message {"JBAS014771: Services with missing/unavailable dependencies"=>["jboss.deployment.subunit.\"appli
      ca.ear\".\"gan_zdb-server.jar\".component.LPStatisticEntityEJB.jdbc.store-manager.INITjboss.data-source.java:jboss/datasources/
      ExampleDSMissing[jboss.deployment.subunit.\"aplica.ear\".\"gan_zdb-server.jar\".component.LPStatisticEntityEJB.jdbc.store-manag
      er.INITjboss.data-source.java:jboss/datasources/ExampleDS]",

       

      ...
      ...

       

       

      How do I tell the entity Beans which Datasource to use?

      Is there a configuration file for defining the default Datasource for the Entities?

       

      Thank you very much

        • 1. Re: Default Datasource for entity beans
          Halli Balli Newbie

          I found out, that a change of the 'datasource jndi-name' to 'java:jboss/datasources/ExampleDS' gets me one step further, my enities seem to deploy.

           

          But can anyone please tell me how can I solve the problem with the jndi name I want to use?

          Where do I have to make changes for my entities?

          Do I have to use a persistence.xml and if so, where do I have to put it?

           

          Thanks in advance.

          • 2. Re: Default Datasource for entity beans
            jaikiran pai Master

            Halli Balli wrote:

             

            But can anyone please tell me how can I solve the problem with the jndi name I want to use?

            Where do I have to make changes for my entities?


            What JNDI name changes?

            • 3. Re: Default Datasource for entity beans
              Halli Balli Newbie

              java:jboss/datasources/ExampleDS is the jndi name for the datasource that is given in the example configuration file.

              I want to use a custom name. But when I try this, I get the error shown above.

              I thougt I could use a jndi name for the datasource like I want and than I have to tell my beans somehow this name.

               

              They all seem to use java:jboss/datasources/ExampleDS by default. And I want to change this.

              Thank you for your reply.

              • 4. Re: Default Datasource for entity beans
                jaikiran pai Master

                Have you deployed a custom datasource of your choice? Take a look at this on how it can be done https://docs.jboss.org/author/display/AS71/Admin+Guide#AdminGuide-Datasources. Once you configure your datasource, you can then use that datasource's JNDI name for the entity beans.

                • 5. Re: Default Datasource for entity beans
                  Halli Balli Newbie

                  Sorry, but may be I am a bit slow or maybe I am not good at describing my problem.

                   

                  1 ) In my first post you can see my definition of the datasource I want to use.

                   

                  2 ) My entities don't have a res-ref because I want to use a container managed persistence.

                   

                  3 ) When I deploy my application using the datasource definition above I get the error that is also in my first post

                  JBAS015870: Deploy of deployment "applica.ear" was rol

                  led back with failure message {"JBAS014771: Services with missing/unavailable dependencies"=>["jboss.deployment.subunit.\"appli

                  ca.ear\".\"gan_zdb-server.jar\".component.LPStatisticEntityEJB.jdbc.store-manager.INITjboss.data-source.java:jboss/datasources/

                  ExampleDSMissing


                  4 )  when I change the datasource jndi name (as described in my second post) to 'java:jboss/datasources/ExampleDS' my enities seem to deploy.

                   

                  5 ) now I want to know what do I have to edit (which file) in order to use my own jndi datasource name?

                  • 6. Re: Default Datasource for entity beans
                    jaikiran pai Master

                    Thanks, I understand the question better now. You can configure that in the jbosscmp-jdbc.xml file (which should be placed in the META-INF folder of your EJB jar). Here's an example:

                     

                    <?xml version='1.0' encoding='UTF-8'?> 
                    <jbosscmp-jdbc> 
                        <defaults> 
                            <datasource>java:jboss/datasources/DataSource</datasource>
                         </defaults>
                    </jbosscmp-jdbc>
                    

                     

                    I'll have to check if there are some detailed examples on its usage.

                    • 7. Re: Default Datasource for entity beans
                      Halli Balli Newbie

                      Hi, thank you.

                       

                      I already have this file in each of my jar-files that contain the EJBs

                      I added the <defaults> part as you described. I think that really worked but now I unfortunately get another error.

                       

                       

                      16:39:47,732 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.subunit."applica.ear"."gan

                      _basicclient-server.jar".component.DocumentEntityEJB.jdbc.store-manager.START: org.jboss.msc.service.StartException in service jboss.deployment.

                      subunit."applica."."gan_basicclient-server.jar".component.DocumentEntityEJB.jdbc.store-manager.START: JBAS010785: Failed start store manager

                              at org.jboss.as.cmp.jdbc.JdbcStoreManagerStartService.start(JdbcStoreManagerStartService.java:46)

                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2

                      .GA]

                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_31]

                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_31]

                              at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_31]

                      Caused by: java.lang.RuntimeException: JBAS010765: Error while creating table: [base_document]

                              at org.jboss.as.cmp.jdbc.JDBCStartCommand.createTable(JDBCStartCommand.java:447)

                              at org.jboss.as.cmp.jdbc.JDBCStartCommand.execute(JDBCStartCommand.java:175)

                              at org.jboss.as.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:233)

                              at org.jboss.as.cmp.jdbc.JdbcStoreManagerStartService.start(JdbcStoreManagerStartService.java:44)

                              ... 5 more

                      Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nõhe von 'base_document'.

                              at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)

                              at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(Unknown Source)

                              at org.jboss.jca.adapters.jdbc.WrappedStatement.executeUpdate(WrappedStatement.java:371)

                              at org.jboss.as.cmp.jdbc.JDBCStartCommand.createTable(JDBCStartCommand.java:439)

                              ... 8 more

                       

                       

                      Do you know why this happens?

                      I wonder what can be wrong with the SQL it is created by the application server or?

                      Do you think I have to tell the server somehow which SQL dialect he has to use?

                      But where?

                       

                      Sorry for my stupid questions

                      • 8. Re: Default Datasource for entity beans
                        Halli Balli Newbie

                        Ok, I found the solution for the second problem.

                        The tablename 'base_document' had was surrounded by [] in the jbosscmp-jdbc.xml

                        I used the SQL profiler. JBoss was calling exec sp_tables to check if the table exists and if not wanted to create the table.

                        The call of sp_tables did not succeed when the tablename [base_document] and therefore jboss wanted to create the table again, which caused the error.

                        I removed the brackets and then it works

                        • 9. Re: Default Datasource for entity beans
                          Christian Inzko Newbie

                          Is it possible to define such a default datasource for the complete EAR instead of adding this datasource to every ejb jar (if only one datasource is used)?

                          • 10. Re: Default Datasource for entity beans
                            Eric Laufer Newbie

                            I have a more or less similar issue.

                             

                            I use some Ejb2 third party libraries in my application. So I would not like to patch all these jar libraries and insert some default configuration in the jbosscmp-jdbc.xml files...O.o

                             

                            So the best solution in my opinion would be to modify the default configuration at server or archive level.

                             

                            I am wondering which server component is telling the CMP engine to take a "ExampleDS" datasource as default. is it hard coded?...or is there any possibility to configure it?

                            • 11. Re: Re: Default Datasource for entity beans
                              jaikiran pai Master

                              Eric Laufer wrote:

                               

                              I have a more or less similar issue.

                               

                              I use some Ejb2 third party libraries in my application. So I would not like to patch all these jar libraries and insert some default configuration in the jbosscmp-jdbc.xml files...O.o

                               

                              So the best solution in my opinion would be to modify the default configuration at server or archive level.

                               

                              I am wondering which server component is telling the CMP engine to take a "ExampleDS" datasource as default. is it hard coded?...or is there any possibility to configure it?

                              It's not hardcoded but isn't configurable either. Ideally it should have been done in the CMP subsystem, but that attribute isn't exposed. However, if you still want to do it at the server level, the ugly way of doing it is:

                               

                              1) Go to JBOSS_HOME/modules/.../org/jboss/as/cmp/main folder

                              2) You'll find a jboss-as-cmp*.jar which contains a standardjbosscmp-jdbc.xml at the root of the jar.

                              3) Unzip the jar, edit that standardjbosscmp-jdbc.xml to change the following couple of lines to something of your choice:

                               

                              <jbosscmp-jdbc>
                              
                                  <defaults>
                                      <datasource>java:jboss/datasources/ExampleDS</datasource>
                                      <datasource-mapping>Hypersonic SQL</datasource-mapping>
                              

                               

                              4) Recreate that updated jar and save it by the same name as earlier.

                               

                              Note: This isn't the right way to do it and it's a hack, but if you are willing to go this way, you can.

                              • 12. Re: Default Datasource for entity beans
                                Eric Laufer Newbie

                                jaikiran pai schrieb:

                                 

                                Eric Laufer wrote:

                                 

                                I have a more or less similar issue.

                                 

                                I use some Ejb2 third party libraries in my application. So I would not like to patch all these jar libraries and insert some default configuration in the jbosscmp-jdbc.xml files...O.o

                                 

                                So the best solution in my opinion would be to modify the default configuration at server or archive level.

                                 

                                I am wondering which server component is telling the CMP engine to take a "ExampleDS" datasource as default. is it hard coded?...or is there any possibility to configure it?

                                It's not hardcoded but isn't configurable either. Ideally it should have been done in the CMP subsystem, but that attribute isn't exposed. However, if you still want to do it at the server level, the ugly way of doing it is:

                                 

                                1) Go to JBOSS_HOME/modules/.../org/jboss/as/cmp/main folder

                                2) You'll find a jboss-as-cmp*.jar which contains a standardjbosscmp-jdbc.xml at the root of the jar.

                                3) Unzip the jar, edit that standardjbosscmp-jdbc.xml to change the following couple of lines to something of your choice:

                                 

                                1. <jbosscmp-jdbc> 
                                2.  
                                3.     <defaults> 
                                4.         <datasource>java:jboss/datasources/ExampleDS</datasource> 
                                5.         <datasource-mapping>Hypersonic SQL</datasource-mapping> 

                                 

                                4) Recreate that updated jar and save it by the same name as earlier.

                                 

                                Note: This isn't the right way to do it and it's a hack, but if you are willing to go this way, you can.

                                Thanks for the quick reply!

                                 

                                Ah ok!...I already read abut the standardjbosscmp-jdbc.xml. In earlier versions of the JBoss AS this file was found in the configuration path of the server...but for the JBoss 7 AS I did not found any equivalent file.

                                 

                                Is there any plan to give a possibility to configure this part to the standard jboss configuration?...Maybe to expose this configuration to the CMP subsystem of the standalone.xml or domain.xml?

                                • 13. Re: Default Datasource for entity beans
                                  jaikiran pai Master

                                  JBoss AS 7.x community version is long EOLed (if I can use that term). Bug fixes and new features are being added in the version 8 (JBoss AS has been renamed to WildFly). WildFly no longer supports CMP. Long story short, no there are no plans for providing this configuration in the community edition.

                                   

                                  On the other hand, if you are a EAP 6.x (which is based on AS7) customer, then maybe you can convince the product side to provide some configuration for the CMP subsystem. It's not guaranteed that you'll get it but that's something the product side and the support team will let you know. So get in touch with the support team through the support portal, if you are a EAP customer.