Продолжаю получать ошибку java.sql.SQLFeatureNotSupportedException на моем jpql - PullRequest
0 голосов
/ 23 мая 2018

Продолжайте получать эту ошибку, когда я пытаюсь извлечь все записи для сущности из базы данных.

[err] javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.1.v20171221-bd47e8f): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgPreparedStatement.getLargeUpdateCount is not yet implemented.
Error Code: 0
Query: ReadAllQuery(referenceClass=Vehicle sql="VEHICLE_ID", "NAME" FROM "VEHICLES"")
[err]   at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:389)
[err]   at [internal classes]
[err]   at com.ibm.op.model.control.vehicles.VehicleScheduler.retrieveVehiclesAtStartUp(VehicleScheduler.java:74)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:498)
[err]   at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:4870)
[err]   at [internal classes]
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:498)
[err]   at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:200)
[err]   at [internal classes]
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:498)
[err]   at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:200)
[err]   at [internal classes]
[err]   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[err]   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[err]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[err]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[err]   at java.lang.Thread.run(Thread.java:748)

Вот код:

@Table(name="\"VEHICLES\"")
@Entity
public class Vehicle {

    @Id
    @NotNull
    @Column(name="\"VEHICLE_ID\"")
    private Long id;


    @NotNull
    @Column(name="\"NAME\"")
    private String name;

    //... Getters and setters
}

@Stateless
public class VehicleScheduler{

    @PersistenceContext
    private EntityManager entityManager;


    @PostConstruct
    public void retrieveVehiclesAtStartUp() {
        try {
            List<Vehicle> vehicles = this.entityManager
                .createQuery("SELECT v FROM Vehicle v", Vehicle.class)
                .getResultList();
            vehicles.forEach((vehicle) -> {
                System.out.println("We got new vehicle " + vehicle.getId());
            });
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Вот файл persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
    <persistence-unit name="local" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/postgres</jta-data-source>
    </persistence-unit>
</persistence>

Где jdbc/postgres - имя поиска jndi, которое мы настраиваем в файле websphere-liberty server.xml.Я использую jpa-2.2, eclipselink-2.7.1, postgresql-42.2.2.jar для драйвера jdbc и сервера базы данных postgresql-9.6. Список функций в server.xml:

   <featureManager>
        <feature>beanValidation-2.0</feature>
        <feature>cdi-2.0</feature>
        <feature>appSecurity-3.0</feature>
        <feature>j2eeManagement-1.1</feature>
        <feature>wasJmsServer-1.0</feature>
        <feature>jaxrs-2.1</feature>
        <feature>webProfile-8.0</feature>
        <feature>jcaInboundSecurity-1.0</feature>
        <feature>jsonb-1.0</feature>
        <feature>managedBeans-1.0</feature>
        <feature>ejbHome-3.2</feature>
        <feature>jaxws-2.2</feature>
        <feature>jsonp-1.1</feature>
        <feature>jaxrsClient-2.1</feature>
        <feature>el-3.0</feature>
        <feature>concurrent-1.0</feature>
        <feature>appClientSupport-1.0</feature>
        <feature>ejbRemote-3.2</feature>
        <feature>jaxb-2.2</feature>
        <feature>mdb-3.2</feature>
        <feature>jacc-1.5</feature>
        <feature>batch-1.0</feature>
        <feature>json-1.0</feature>
        <feature>jaspic-1.1</feature>
        <feature>distributedMap-1.0</feature>
        <feature>websocket-1.1</feature>
        <feature>wasJmsSecurity-1.0</feature>
        <feature>wasJmsClient-2.0</feature>
        <feature>ejbLite-3.2</feature>
        <feature>localConnector-1.0</feature>
        <feature>jdbc-4.2</feature>
        <feature>jpa-2.2</feature>
        <feature>jndi-1.0</feature>
        <feature>jpaContainer-2.2</feature>
    </featureManager>

Что такоеЯ делаю не так?Почему запрос JPQL не выполняется правильно?

Я нашел это в журналах профиля websphere liberty

Exception = java.sql.SQLFeatureNotSupportedException
Source = com.ibm.ws.rsadapter.jdbc.v42.WSJdbc42PreparedStatement.closeWrapper
probeid = 310
Stack Dump = java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgPreparedStatement.getLargeUpdateCount is not yet implemented.
    at org.postgresql.Driver.notImplemented(Driver.java:683)
    at org.postgresql.jdbc.PgStatement.getLargeUpdateCount(PgStatement.java:998)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:428)
    at com.sun.proxy.$Proxy90.getLargeUpdateCount(Unknown Source)
    at com.ibm.ws.rsadapter.jdbc.v42.WSJdbc42PreparedStatement.getCompatibleUpdateCount(WSJdbc42PreparedStatement.java:51)
    at com.ibm.ws.rsadapter.impl.DatabaseHelper.getUpdateCount(DatabaseHelper.java:336)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:306)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:152)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:110)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.closeStatement(DatabaseAccessor.java:414)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.releaseStatement(DatabaseAccessor.java:1700)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:709)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:564)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2093)
    at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:600)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:270)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:256)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:327)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:722)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
    at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:563)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1221)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:911)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1180)
    at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:464)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1268)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2979)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1892)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1874)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:480)
    at com.ibm.op.model.control.vehicles.VehicleScheduler.retrieveVehiclesAtStartUp(VehicleScheduler.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:4870)
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:651)
    at com.ibm.ws.cdi.ejb.impl.InterceptorChain.proceed(InterceptorChain.java:119)
    at com.ibm.ws.cdi.ejb.impl.EJBCDIInterceptorWrapper.invokeInterceptors(EJBCDIInterceptorWrapper.java:131)
    at com.ibm.ws.cdi.ejb.impl.EJBCDIInterceptorWrapper.aroundTimeout(EJBCDIInterceptorWrapper.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:200)
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:631)
    at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:81)
    at com.ibm.ws.cdi.ejb.interceptor.WeldSessionBeanInterceptorWrapper.aroundInvoke(WeldSessionBeanInterceptorWrapper.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:200)
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:631)
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.doAroundInterceptor(InvocationContextImpl.java:305)
    at com.ibm.ejs.container.interceptors.InvocationContextImpl.doAroundInvoke(InvocationContextImpl.java:272)
    at com.ibm.ejs.container.EJSContainer.invoke(EJSContainer.java:4772)
    at com.ibm.ejs.container.TimedObjectWrapper.invokeCallback(TimedObjectWrapper.java:87)
    at com.ibm.ejs.container.TimerNpRunnable.doWork(TimerNpRunnable.java:195)
    at com.ibm.ejs.container.TimerNpRunnable.run(TimerNpRunnable.java:102)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

1 Ответ

0 голосов
/ 24 мая 2018

Глядя на исходный код PostgreSQL, драйвер JDBC заявляет, что он совместим с JDBC 4.2:

https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/util/DriverInfo.java

Однако в нем не реализованы новые методы JDBC 4.2.В этом случае Statement.getLargeUpdateCount(): https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgStatement.java#L997

Таким образом, EclipseLink не может заранее знать, будет ли вызов Statement.getLargeUpdateCount() работать или нет (поскольку драйвер сообщает, что он соответствует 4.2).Однако EclipseLink, вероятно, может обрабатывать исключение SQLFeatureNotSupported лучше, чем выбрасывает PgStatement.getLargeUpdateCount().Обновление вашего вопроса с помощью полной трассировки стека поможет более точно диагностировать проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...