9 Replies Latest reply: Aug 29, 2012 7:42 AM by Christian Inzko 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)?