I m using the latest EclipseLink version with MySQL 5.5 (table type InnoDB). I m inserting about 30900 records (which could be also more) at a time. The problem is, that the insert performance is pretty poor: it takes about 22 seconds to insert all records (compared with JDBC: 7 seconds). I ve read that using batch writing should help - but doesn t!?
@Entity
public class TestRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public int test;
}
添加记录的准则:
factory = Persistence.createEntityManagerFactory("xx_test");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
for(int i = 0; i < 30900; i++) {
TestRecord record = new TestRecord();
record.test = 21;
em.persist(record);
}
em.getTransaction().commit();
em.close();
And finally my EclipseLink configuration:
<persistence-unit name="xx_test" transaction-type="RESOURCE_LOCAL">
<class>com.test.TestRecord</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/xx_test" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="test" />
<property name="eclipselink.jdbc.batch-writing" value="JDBC" />
<property name="eclipselink.jdbc.cache-statements" value="true"/>
<property name="eclipselink.ddl-generation.output-mode" value="both" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
What I m doing wrong? I ve tried several setting, but nothing seems the help. Thanks in advance for helping me! :)
- 狂热
还有一点是,在连接器使用的URL数据中添加<代码>?rewriteBatstalments=true。
这导致执行约120 300字的插入约30个,以前约60个。