-1
我正在開發jsf與jpa項目現在我在大容量插入問題關於列表大小超過6000這意味着它應該在表中插入超過6000個記錄,但它只插入215個記錄。jpa批量插入沒有正確插入
我的代碼是在這裏
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
try {
em.getTransaction().begin();
for (int i = 0; i < sgmlList.size(); i++) {
// Getting the object from the list by using loop
SGML sgml = sgmlList.get(i);
em.persist(sgml);
}
em.getTransaction().commit();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("SGML imported successfully"));
} catch (Exception ex) {
} finally {
if (em != null) {
em.close();
}
}
和我的堅持XML是
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="Cation" transaction-type="RESOURCE_LOCAL">
<class>com.cation.bean.Users</class>
<class>com.cation.bean.BatchInfo</class>
<class>com.cation.bean.SGML</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://192.168.1.4:3306/cation"/>
<property name="javax.persistence.jdbc.user" value="rix"/>
<property name="javax.persistence.jdbc.password" value="rix123"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
我試過這個代碼還當它持續的對象列表
if (i % 200 == 0) {
em.flush();
em.clear();
}
但那麼也會出現同樣的問題。任何人都可以幫助解決這個問題PLZ。
任何人都可以幫助我解決這個問題 – user2476979