0

我尝试从 Apache TomEE Plume 从 1.7.4 迁移到 8.0.0-M2,并且有些东西在以前的版本中有效,但不适用于新版本。

我有资源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"/>

它用作persistence.xml文件中的数据源

<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>

这样的配置在 1.7.4 中运行良好,在 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();

控制台输出

[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)
.....

在此日志中清楚地看到 JPA 尝试连接到 HSQL 数据库,尽管在配置中指向 MS SQL。我试图在实体管理器中查看连接字符串及其真实性。

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();
}

控制台输出 8.0.0

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

但在 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;

8.0.0 中的哪些新设置需要更改才能正常工作?为什么正确的连接改为hsql连接?也许这是这个运行时的默认连接,而 tomee 8.0.0 只是读取旧设置失败,不是吗?

服务器启动时也有警告

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
4

0 回答 0