0

I am developping a web application (Eclipse, TomEE) and I try to communicate with a MySQL database :

  • I have created the database
  • I have included EclipseLink and MySQL-Driver
  • the connection is OK (I tried the ping and it is OK)

When I try to persist the data I have this error

Grave: could not reopen database
org.hsqldb.HsqlException: Database lock acquisition failure: lockFile:org.hsqldb.persist.LockFile@81911f7a[file =C:\Program Files\eclipse\data\hsqldb\hsqldb.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: C:\Program Files\eclipse\data\hsqldb\hsqldb.lck (Le chemin d’accès spécifié est introuvable)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source)
    at org.hsqldb.persist.Logger.acquireLock(Unknown Source)
    at org.hsqldb.persist.Logger.open(Unknown Source)
    at org.hsqldb.Database.reopen(Unknown Source)
    at org.hsqldb.Database.open(Unknown Source)
    at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
    at org.hsqldb.DatabaseManager.newSession(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
    at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
    ...

I don't understand why it is about hsqldb whereas I have configured MySQL

I have in src/META-INF the persistence.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">


    <persistence-unit name="UP" transaction-type="JTA"> 
        <class>jpa.User</class>
</persistence-unit>
</persistence>

and I call the entityManager like this :

@Stateless
public class UserFacade extends AbstractFacade<User> implements UserFacadeLocal {
    @PersistenceContext (unitName="UP")
    private EntityManager em;
    ...
}
federem
  • 299
  • 1
  • 6
  • 17

3 Answers3

2

you need to define your datasource in tomee.xml (http://tomee.apache.org/common-datasource-configurations.html ) and specify the name you defined on tomee.xml (id) in your persistence.xml as jta-data-source.

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13
0

You need to add:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

to persistence.xml file.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
cchacin
  • 1
  • 1
0
  1. Check if you are using TomEE, not Tomcat, because TomEE have JPA.
  2. You need to put the configuration file resources.xml in the folder \src\main\webapp\WEB-INF.

Example:

<tomee>
    <Resource id="MySQL Database" type="DataSource">
        JdbcDriver com.mysql.cj.jdbc.Driver
        JdbcUrl jdbc:mysql://localhost/<your_schema>
        UserName root
        Password root
    </Resource>
</tomee>

Be sure that you are using the right directories locations for your xml's (that error make me lost much time)!

  1. Refer to your resource id as your data source in your persistence.xml:

    <persistence-unit name="example-persistence-unit">
        <jta-data-source>MySQL Database</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property
                    name="jakarta.persistence.schema-generation.database.action"
                    value="drop-and-create"/>
            <property name="eclipselink.logging.level" value="ALL"/>
        </properties>
    </persistence-unit>
    

Optionally, enable eclipselink.logging.level to ALL to see details of eventually other problems (if you are using this implementation).

  1. Create your schema in the database with the same name as in the JdbcUrl.
  2. Deploy!