0
我打破了自己的這個問題,我需要一些幫助。我想編輯查詢,但我不斷收到此錯誤GAE JPA嘗試從查詢中編輯實體時出現非法參數
javax.persistence.PersistenceException: Illegal argument
...
Caused by: java.lang.IllegalArgumentException: operating on too many entity groups in a single transaction.
...
這是代碼的部分我用它來更新記錄
final EntityManager em = PersistenceManager.getInstance().getEntityManagerFactory().createEntityManager();
try {
//em.getTransaction().begin();
{
Query q = em.createQuery(String.format("SELECT FROM %s cat", NewsContent.class.getSimpleName()));
int count = 0;
for(NewsContent nc : (List<NewsContent>) q.getResultList()){
nc.setOrderTimestamp(nc.getTimestamp());
count++;
}
resp.setContentType("text/plain");
resp.getWriter().println("NewsContent:\n\t Updated " + count + " records\n");
}
//em.getTransaction().commit()
} finally {
//if(em.getTransaction().isActive())
// em.getTransaction().rollback();
em.close();
}
這是persistance.xml
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
<property name="datanucleus.singletonEMFForName" value="true"/>
</properties>
部分
這是JPA實體(我刪除了setter和getters)
@Entity
public class NewsContent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Key ID;
String api_key;
String author_username;
String author_displayname;
String organization;
String organization_displayname;
long timestamp;
String api_type;
long order_timestamp;
Text text = null;
String title = null;
String title2 = null;
String extra = null;
String extra_desc = null;
Boolean featured = false;
String category = null;
String imageID = null;
String image_serving_url = null;
}
有什麼想法?
是否含有setOrderTimestamp拋出異常的行?這個軟件本身看起來是正確的,但是隻有一個實體被訪問。這表明應用程序中的其他代碼可能有未提交的事務。 –
其實它em.close();導致這一點。 – BlackCat