I think the same scenario I have.
After rummaging through every forum, I could not find a final answer on how
to
use a MySql server db in Embedded EJB3.1 container.
It seems the Embedded EJB Container configured in a way that it uses the
JavaDB
as its default data source.
I gonna use a mysql data source in embedded ejb but nothing has helped yet.
Note that it seems when unit testing my ejbs through Maven, the
persistence.xml
in src/test/resources/META-INF is not considered and instead the
persistence.xml
in src/main/resources/META-INF is regarded. Therefore, every time I have to
comment <jta-data-source>…</jta-data-source> when unit testing. I guess this
may
also be the source of the answer.
Please let me know how to set Embedded EJB Container in a way to use MySql
server data source instead of JavaDB.
My persistence.xml snapshot for example;
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="
http://java.sun.com/xml/ns/persistence">
<persistence-unit name="WebShopPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<!--When Embedded EJB mode is used in testing, the following line must be
removed. The Derby database is created in [Java User
Home\Dir]\sun-appserv-samples folder by default. (Use sysinfo command of
Derby to see where the Java User Home\Dir is.)-->
<!--<jta-data-source>jdbc/webshop</jta-data-source>-->
<class>org.youness.webshop.entity.product.Producer</class>
<properties>
<!--<property name="javax.persistence.jdbc.driver"
value="com.mysql.jdbc.Driver"/>-->
<!--<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/WebShop"/>-->
<!--<property name="javax.persistence.jdbc.user" value="root"/>-->
<!--<property name="javax.persistence.jdbc.password" value="214126"/>-->
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
Kind regards
Youness
On Sun, Mar 7, 2010 at 8:38 PM, Antonio Goncalves <antonio.mailing_at_gmail.com
> wrote:
> Hi,
>
> I'm running a very simple example with an EJB and an entity. I use a Main
> class to trigger the EJBContainer and persist the entity in the database. It
> works fine if I use the jdbc/__default datasource in the persistence.xml
> file. But what if I need to change to another custom datasource ? How do I
> define a new datasource in an embedded environment ?
>
> Thanks,
> Antonio
>