1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[JBoss] Unable to delete default H2 Datasource in JBoss EAP 6.4 and use my MySQL Datasource as...

Discussão em 'StackOverflow' iniciado por Stack, Outubro 17, 2024 às 06:52.

  1. Stack

    Stack Membro Participativo

    I am having a challenge with JBoss EAP 6.4. I would like my application which is using EJB 2.x Entity Beans to use the mysql datasource that I added in the standalone.xml configuration.

    I added a new MySQL Datasource in the standalone.xml configuration and I deployed the application and invoked my Entity Bean, it was defaulting to the H2 Datasource. I tried deleting the H2 datasource in the standalone.xml file and then my application couldn't start.

    My application has EJB 2.x entity bean similar to this one:

    ejb-jar.xml

    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
    JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <enterprise-beans>
    <entity>
    <ejb-name>FoodEntity</ejb-name>
    <home>com.example.FoodEntityHome</home>
    <remote>com.example.FoodEntity</remote>
    <ejb-class>com.example.FoodEntityBean</ejb-class>
    <persistence-type>Container</persistence-type>

    <prim-key-class>java.lang.String</prim-key-class>

    <reentrant>false</reentrant>

    <cmp-version>2.x</cmp-version>
    <abstract-schema-name>FoodEntity</abstract-schema-name>

    <cmp-field>
    <field-name>id</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>name</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>description</field-name>
    </cmp-field>


    <primkey-field>id</primkey-field>

    <query>
    <query-method>
    <method-name>findByName</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT DISTINCT OBJECT(p) FROM FoodEntity p WHERE
    p.name =?1</ejb-ql>
    </query>
    </entity>
    </enterprise-beans>
    <assembly-descriptor>
    <method-permission>
    <unchecked/>
    <method>
    <ejb-name>FoodEntity</ejb-name>
    <method-name>*</method-name>
    </method>
    </method-permission>
    </assembly-descriptor>
    </ejb-jar>


    Datasource configuration in standalone.xml

    <subsystem xmlns="urn:jboss:domain:datasources:1.2">
    <datasources>
    <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:mysql://X.X.X.X:3306/test</connection-url>
    <driver>mysql</driver>
    <security>
    <user-name>test</user-name>
    <password>test</password>
    </security>
    <validation>
    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
    </validation>
    </datasource>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="false">
    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
    <driver>h2</driver>
    <security>
    <user-name>sa</user-name>
    <password>sa</password>
    </security>
    </datasource>
    <drivers>
    <driver name="mysql" module="com.mysql">
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    </driver>
    <driver name="h2" module="com.h2database.h2">
    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
    </driver>
    </drivers>
    </datasources>
    </subsystem>


    I also have a ~/jboss-eap-6.4/modules/com/mysql/main/ directory with module.xml and the mysql-connector-java-5.1.47-bin.jar driver.

    module.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.1" name="com.mysql">
    <resources>
    <resource-root path="mysql-connector-java-5.1.47-bin.jar"/>
    </resources>
    <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    </dependencies>
    </module>


    Can you kindly give me an idea on how I can tell my FoodEntity entity bean to use the MySQL Datasource instead of the default H2 Datasource. When I invoke my entity bean i can successfully create and retrieve FoodEntities from the H2 Datasource but now I want to be able to do that with my MySQL Datasource.

    The reason why I am sticking to EJB 2.x entity beans is because I would like to have that backward compatibility support at the same time for new entities I will be using JPA and EJB 3.x annotations.

    Continue reading...

Compartilhe esta Página