有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么数据源不匹配从TomEE 1.7.4迁移到8.0.0M2?

我尝试从ApacheTomee 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"/>

它在持久化中用作数据源。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

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

共 (0) 个答案