2017-03-10 7 views
0

レコードを保持しない次のメソッドがあります。サーブレットから別のクエリを実行し、残りのサービスによって更新された後にこのレコードを表示すると、変更が表示されません。それが永続しない理由は何ですか?また、私は運でflush()および/またはclear()で試してみた:ここJetty + Hibernate + JPAトランザクションがH2で持続しない

@POST 
@Path("translations") 
@Produces({MediaType.APPLICATION_JSON}) 
@Consumes({MediaType.APPLICATION_JSON}) 
public Translation updateTranslationValue(Translation translation,  
@Context HttpServletRequest request) { 
    request.getSession().setAttribute("reload_xlate", true); 
    EntityManager em = entityManagerFactory.createEntityManager(); 
    em.getTransaction().begin(); 

    TypedQuery<Translation> query = em.createQuery(
      "SELECT t FROM Translation t WHERE t.key = :key", Translation.class); 
    query.setParameter("key", translation.getKey()); 
    Translation mappedTranslation = query.getSingleResult(); 
    mappedTranslation.setValue(translation.getValue()); 
    L.info("Updated: {}", mappedTranslation); 
    //em.flush(); 
    //em.clear(); 
    em.getTransaction().commit(); 
    em.close(); 
    return mappedTranslation; 
} 

は私のpersistence.xmlです:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" 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_1.xsd"> 
    <persistence-unit name="MyJPAJAXRS" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
    <non-jta-data-source>jdbc/myds</non-jta-data-source> 
    <properties> 
     <property name="javax.persistence.schema-generation.database.action" 
       value="drop-and-create"/> 
     <property name="javax.persistence.sql-load-script-source" value="META-INF/seed.sql"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

マイ桟橋データソースは次のとおりです。

<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> 
    <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> 
     <Arg>jdbc/myds</Arg> 
     <Arg> 
      <New class="com.zaxxer.hikari.HikariDataSource"> 
       <Arg> 
        <New class="com.zaxxer.hikari.HikariConfig"> 
         <!--<Set name="minimumPoolSize">5</Set>--> 
         <!--<Set name="maximumPoolSize">20</Set>--> 
         <Set name="dataSourceClassName"> 
          org.h2.jdbcx.JdbcDataSource 
         </Set> 
         <Call name="addDataSourceProperty"> 
          <Arg>url</Arg> 
          <Arg>jdbc:h2:mem:test_mem</Arg> 
         </Call> 
        </New> 
       </Arg> 
      </New> 
     </Arg> 
    </New> 
</Configure> 

答えて

0

ターンH2の場合、データベースプールの設定を1接続のみに変更する必要があります。

<Set name="minimumPoolSize">1</Set> 
<Set name="maximumPoolSize">1</Set> 

それはトリックでした。

関連する問題