JTA Eclipselink 提交后不更新实体

JTA Eclipselink not update entities after commit

我在带有 Wildfly 8 的 JTA 中使用 Eclipselink,问题是在提交用户事务并将数据插入数据库后它不会更新相关实体,因此如果我重新加载页面或打开页面的新实例它加载没有插入行的数据。

@ManagedBean
@ViewScoped
public class empcreator {

UserTransaction ut=null;

@PersistenceContext(unitName="game")
private EntityManager em;

Context icontext=null;
public empcreator() throws NamingException{
    icontext=new InitialContext();
    ut=(UserTransaction)icontext.lookup("java:comp/UserTransaction");
}

持久化方法是:

    public void addElementToIsland() throws NamingException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException{
    int objectid=Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("objectid"));
    int x=Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("x"));
    int y=Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("y"));
    int z=Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("z"));
    int r=Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("r"));
    int islid=selectedisland;

    Query q=em.createNamedQuery("Element.findOne");
    q.setParameter("id", objectid);
    Element element=(Element)q.getResultList().get(0);

    q=em.createNamedQuery("Island.findOne");
    q.setParameter("islandid", islid);
    Island isl=(Island)q.getResultList().get(0);

    islandsobjects el=new islandsobjects();
    el.setElement(element);
    el.setX(x);
    el.setY(y);
    el.setZ(z);
    el.setR(r);
    el.setIsland(isl);

    ut.begin();
    em.persist(el);
    ut.commit();
}

加载函数为:

    public void loadIsland(ActionEvent e){
    Query q=em.createNamedQuery("Island.findOne");
    q.setParameter("islandid", selectedisland);
    List<islandsobjects> iobjects=((Island)q.getResultList().get(0)).getIobjects();
    JsonObjectBuilder jsonOB=Json.createObjectBuilder();
    JsonArrayBuilder jsonAB=Json.createArrayBuilder();
    for(int i=0;i<iobjects.size();i++){
        jsonOB.add("id", iobjects.get(i).getId());
        Element element=iobjects.get(i).getElement();
        jsonOB.add("name", element.getName());
        jsonOB.add("x", iobjects.get(i).getX());
        jsonOB.add("y", iobjects.get(i).getY());
        jsonOB.add("z", iobjects.get(i).getZ());
        jsonOB.add("r", iobjects.get(i).getR());
        jsonOB.add("objectid", iobjects.get(i).getObjectid());
        jsonOB.add("islandid", selectedisland);
        jsonAB.add(jsonOB);
    }
    JsonObject jsElements=Json.createObjectBuilder().add("elements", jsonAB).build();
    RequestContext.getCurrentInstance().execute("loadisland("+jsElements.toString()+")");
}

这是persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="game" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/boddooo</jta-data-source>
    <class>boddooo.entity.Empire</class>
    <class>boddooo.entity.Empiresobject</class>
    <class>boddooo.entity.Island</class>
    <class>boddooo.entity.Element</class>
    <class>boddooo.entity.User</class>
    <class>boddooo.entity.World</class>
    <class>boddooo.entity.islandsobjects</class>
      <properties>
          <property name="eclipselink.target-server" value="JBoss"/>
          <property name="eclipselink.logging.level" value="FINE"/>
          <property name="eclipselink.persistence-context.flush-mode" value="auto" />
      </properties>
</persistence-unit>
</persistence>

我也将刷新模式更改为提交但没有结果。

当我禁用缓存时它解决了问题但变得更慢然后我使用这个

query.setHint("javax.persistence.cache.storeMode", "REFRESH");

它在不禁用缓存的情况下更新了数据