Почему JPA EntityManager Блокирует Выполнение Кода?

#jpa #entitymanager #blocked

Вопрос:

У меня есть следующий код:

  try (Connection con = DataBase.getConnection(); final java.sql.Statement stmt = con.createStatement()) {
            con.setAutoCommit(false);
            stmt.execute(" update t_vers set Descr = 'dom' where Descr = ''");
            final Connection conn2 = DataBase.getConnection();
            final PreparedStatement p = conn2.prepareStatement("select * from T_VERS");
            final ResultSet rs = p.executeQuery();
            rs.next();
            final Long docNr = rs.getLong(1);
            final EntityManager em = DataBase.createEntityManager();
            final List<Vers> vers = em.createNamedQuery("T_Vers_Custom.findAll", Vers.class).getResultList();
            conn2.close();
            con.commit();
            con.setAutoCommit(true);
        } catch (final SQLException e) {} 
 

Внутри транзакции I с прямым JDBC я выполняю запрос с новым соединением с JDBC. Это работает. Когда я пытаюсь выполнить тот же запрос с помощью JPA, процесс блокируется. Последующее чтение сокета не вернет эннимор:

 SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]    
SocketInputStream.socketRead(FileDescriptor, byte[], int, int, int) line: not available 
SocketInputStream.read(byte[], int, int, int) line: not available   
SocketInputStream.read(byte[], int, int) line: not available    
TDSChannel.read(byte[], int, int) line: 1647    
TDSReader.readPacket() line: 3694 [local variables unavailable] 
SQLServerPreparedStatement$PrepStmtExecCmd(TDSCommand).startResponse(boolean) line: 5022    
SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement$PrepStmtExecCmd) line: 388 
SQLServerPreparedStatement$PrepStmtExecCmd.doExecute() line: 524    
SQLServerPreparedStatement$PrepStmtExecCmd(TDSCommand).execute(TDSWriter, TDSReader) line: 7418 
SQLServerConnection.executeCommand(TDSCommand) line: 3274   
SQLServerPreparedStatement(SQLServerStatement).executeCommand(TDSCommand) line: 247 
SQLServerPreparedStatement(SQLServerStatement).executeStatement(TDSCommand) line: 222   
SQLServerPreparedStatement.executeQuery() line: 446 
WrappedPreparedStatementJDK8(WrappedPreparedStatement).executeQuery() line: 504 
ResultSetReturnImpl.extract(PreparedStatement) line: 70 
QueryLoader(Loader).getResultSet(PreparedStatement, RowSelection, LimitHandler, boolean, SessionImplementor) line: 2117 
QueryLoader(Loader).executeQueryStatement(String, QueryParameters, boolean, List<AfterLoadAction>, SessionImplementor) line: 1900   
QueryLoader(Loader).executeQueryStatement(QueryParameters, boolean, List<AfterLoadAction>, SessionImplementor) line: 1876   
QueryLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean, ResultTransformer) line: 919  
QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean, ResultTransformer) line: 336   
QueryLoader(Loader).doList(SessionImplementor, QueryParameters, ResultTransformer) line: 2617   
QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2600  
QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2429    
QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set<Serializable>, Type[]) line: 2424 
QueryLoader.list(SessionImplementor, QueryParameters) line: 501 
QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 371 
HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 216 
SessionImpl.list(String, QueryParameters) line: 1326    
QueryImpl.list() line: 87   
QueryImpl<X>.list() line: 606   
QueryImpl<X>.getResultList() line: 483  
 

Я попытался сравнить соединения JDBC между обычным JDBC и JPA. Я не мог найти никакой разницы. Итак, почему этот запрос на запрос результата из БД блокируется JPA и то же самое работает с обычным JDBC?