Configure a DataSource for MySQL and TomEE tutorial

Updated:

Copy the driver of MySql in the TomEE lib directory:

Mysql

You have to modify the config file tomEE/conf/tomee.xml

In the file you have to add your mysql configuration:

Tomee
<Resource id="pmone" type="DataSource"> 
JdbcDriver com.mysql.jdbc.Driver 
JdbcUrl jdbc:mysql://localhost:3306/pm 
UserName user 
Password secret 
JtaManaged true 
</Resource> 

Your persistence xml has to use the datasource defined in tomee.xml (in this case ‘phone’)

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="https://java.sun.com/xml/ns/persistence" 
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="https://java.sun.com/xml/ns/persistence 
  
https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
  
<persistence-unit name="pmWebPU"> 
<jta-data-source>pmone</jta-data-source> 
<exclude-unlisted-classes>false</exclude-unlisted-classes> 
  
<properties> 
  
</properties> 
</persistence-unit> 
</persistence> 

Done 🙂

You could be interested in

Multiple Persistence with EclipseLink


Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).