Question

I'm learning Java EE and I am currently trying to use a derby database with a Tomee server.

I declared my datasource in (tomee-path)/conf/tomee.xml like this:

<Resource id="IsiDrive" type="DataSource">
    JdbcDriver = org.apache.derby.jdbc.EmbeddedDriver
    JdbcUrl    = jdbc:derby://localhost:1527/isidrive
    JtaManaged  true
</Resource>

And my persistence.xml file located in (project-path)/src/META-INF/persistence.xml contains the following:

<?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="IsiDrive">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
            <jta-data-source>IsiDrive</jta-data-source>

    <class>model.Banana</class>
</persistence-unit>

When I launch the server and try to access the database with simple method:

public class Controller {
    @PersistenceContext(unitName = "IsiDrive") 
    EntityManager em;

    public void test() {
        Query q = em.createQuery("SELECT u FROM Banana u");
        List<Banana> userList = q.getResultList(); //error
    }
}

I got the following logs:

Starting OpenJPA 2.3.0-nonfinal-1540826
Using dictionary class "org.apache.openjpa.jdbc.sql.HSQLDictionary" (HSQL Database Engine 2.3.0 ,HSQL Database Engine Driver 2.3.0).
Connected to HSQL Database Engine version 2.2 using JDBC driver HSQL Database Engine Driver version 2.3.0.2
PM org.apache.openejb.core.transaction.EjbTransactionUtil handleSystemException
EjbTransactionUtil.handleSystemException: user lacks privilege or object not found: BANANA {SELECT t0.id, t0.title FROM Banana t0} [code=-5501, state=42501]
<openjpa-2.3.0-nonfinal-1540826-r422266:1542644 fatal general error> org.apache.openjpa.persistence.PersistenceException: user lacks privilege or object not found: BANANA {SELECT t0.id, t0.title FROM Banana t0} [code=-5501, state=42501]
FailedObject: SELECT u FROM Banana u [java.lang.String]

I don't understand why Tomee tries to use HSQL since I want to use Derby and declared my datasource as it?

edit: error occurs even if I try to use an HSQL DB or MYSQL one. And it is always the same.

Was it helpful?

Solution

Ok nevermind. I should not have put my data source in (tomEE-path)/conf/tomee.xml, but in(myworkspace-path)/Servers/Tomcat v7.0 Server at localhost-config/tomee.xml instead. Silly error, neither Eclipse nor TomEE generates an error about a datasource in persistence.xml that could not be found...

OTHER TIPS

Chech your logs for "auto adjusting" info, it can help you to get the issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top