0

I try to migrate from Apache TomEE Plume from 1.7.4 to 8.0.0-M2 and there are some things which were working in the previous version and do not working with the new release.

I have resource in context.xml

<Resource 
    auth="Container" 
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
    maxTotal="10000" 
    maxIdle="1000" 
    maxPoolSize="10000" 
    maxWaitMillis="-1" 
    name="jdbc/datasource" 
    password="password" 
    type="javax.sql.DataSource" 
    url="jdbc:sqlserver://127.0.0.1:1433;databaseName=database;applicationName=app" 
    username="usr" 
    validationQuery="select @@version"/>

It used as data source in persistence.xml file

<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="gispte" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/datasource</non-jta-data-source>
        <class>model.UserContactType</class>
    </persistence-unit>
</persistence>

Such configuration work nicely in 1.7.4 and throw errors when be data accessing in 8.0.0

EntityManager em = factory.createEntityManager();
TypedQuery<UserContactType> q = em.createQuery("select uct from UserContactType uct order by uct.name", UserContactType.class);
return q.getResultList();

console output

[EL Warning]: 2019-05-01 18:35:52.725--UnitOfWork(1787752065)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERCONTACTTYPE
Error Code: -5501
Call: SELECT id, name FROM usercontacttype ORDER BY name
Query: ReadAllQuery(referenceClass=UserContactType sql="SELECT id, name FROM usercontacttype ORDER BY name")
мая 01, 2019 6:35:52 PM org.apache.openejb.core.transaction.EjbTransactionUtil handleSystemException
SEVERE: EjbTransactionUtil.handleSystemException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERCONTACTTYPE
Error Code: -5501
Call: SELECT id, name FROM usercontacttype ORDER BY name
Query: ReadAllQuery(referenceClass=UserContactType sql="SELECT id, name FROM usercontacttype ORDER BY name")
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERCONTACTTYPE
Error Code: -5501
Call: SELECT id, name FROM usercontacttype ORDER BY name
Query: ReadAllQuery(referenceClass=UserContactType sql="SELECT id, name FROM usercontacttype ORDER BY name")
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
.....
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERCONTACTTYPE
Error Code: -5501
Call: SELECT id, name FROM usercontacttype ORDER BY name
Query: ReadAllQuery(referenceClass=UserContactType sql="SELECT id, name FROM usercontacttype ORDER BY name")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
.....
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERCONTACTTYPE
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
.....

At this log clearly seen that JPA try to connect to HSQL database, although in config pointed MS SQL. I tried to see connection string in entity manager and its true.

EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
try {
    Connection con = em.unwrap(java.sql.Connection.class);
    if ( con == null ) {
        System.out.println("failed get connection from entity manager");
    } else {
        System.out.println("connection url from entity manager\n"+con.getMetaData().getURL());
    }
} catch (Exception e) {
    e.printStackTrace();
} finally {
    em.getTransaction().commit();
}

console output 8.0.0

connection url from entity manager
jdbc:hsqldb:file:D:\src\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\data\hsqldb\hsqldb

But it is correct working in tomee 1.7.4

connection url from entity manager
jdbc:sqlserver://127.0.0.1:1433;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=database;applicationName=app;applicationIntent=readwrite;

What new settings in 8.0.0 need to change for correct work? Why do correct connection changed to hsql connection? Perhaps it is default connection in this runtime and tomee 8.0.0 just failed read old setting, is not it?

Also warnings on server starting

may 01, 2019 7:38:58 PM sun.reflect.NativeMethodAccessorImpl invoke
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:app' did not find a matching property.
.....
may 01, 2019 7:32:20 PM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: app/jdbc/datasource but this one is a JTA datasource
may 01, 2019 7:32:20 PM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: ROOT/jdbc/datasource but this one is a JTA datasource
may 01, 2019 7:32:20 PM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: ROOT/jdbc/datasource but this one is a JTA datasource
MWiesner
  • 8,868
  • 11
  • 36
  • 70
  • Try to add `jtaManaged = false` to your Resource definition. By documentation: http://tomee.apache.org/datasource-config.html this is `true` by default. If set to `false`, the container will explicitly create a **non**-JTA datasource which you require for your application. Please report back if that helped. If so, I will provide an answer with more details. – MWiesner May 18 '19 at 19:23
  • I tried to do it, but it do not help. may 22, 2019 1:44:10 PM org.apache.openejb.assembler.classic.Assembler createRecipe INFO: Creating Resource(id=My DataSource) may 22, 2019 1:44:26 PM org.apache.openejb.config.AutoConfig deploy WARNING: Found matching datasource: gispte/jdbc/datasource but this one is a JTA datasource And i detected that apache try to create resource with id "My DataSource", but it is not defined in context.xml – Sayfulla Koneev May 22 '19 at 10:58

0 Answers0