English 中文(简体)
EclipseLink在插入数据方面非常缓慢
原标题:EclipseLink very slow on inserting data

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个。

最佳回答
@GeneratedValue(strategy = GenerationType.IDENTITY)

永远不建议转至TABLE的顺序,也不建议采用身份识别,也不是一个主要的业绩问题。

See, http://java-persistence-performance.blogspot.com/2011/06/how-to-improve-jpa-performance-by-1825.html

我似乎记得,如果没有一些数据库的配置,我的SQL可能不会支持批量书写,而还有另一个员额,我忘记了这个词,但你或许可以寻找。

问题回答

JDBC Batch writing improves performance drastically; please try it

例如:property name=“eclipselink.jdbc.batch-写作”价值=“JDBC”

也许除了地图转换外,最大的差异是沥滤。 由于EclipseLink缺席,每个实体都处于持续状态(EntityManager),然后在完成承诺时,它们必须将其全部添加到海滩上。

One thing to try for now is:

  1. measure how long an em.flush() call takes after the loop but before the commit. Then if you want you could call em.clear() after the flush so that the newly inserted entities are not merged into the cache.

Doug





相关问题
JPA and PostgreSQL

I m on a project that uses the EclipseLink implementation of JPA to talk to a PostgreSQL database. I have a task for which PostgreSQL NOTIFY/LISTEN seems like a perfect fit. Unfortunately, I m a JPA ...

EclipseLink JPA `@PreUpdate` call not persisting

I ran into some similar questions on StackOverflow, tried the solutions, but did not find an answer. I am using a fairly common JPA strategy to set last modified times on some entities. Set up the ...

EclipseLink, EntityManager with two persistence units needed

I have one jar library A (or project in eclipse), which has it s own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is ...