MySQL 5.5で最新のEclipseLinkバージョン(テーブルタイプInnoDB)を使用しています。私は一度に約30900のレコードを挿入しています。 問題は、挿入パフォーマンスが非常に悪いことです。すべてのレコードを挿入するのに約22秒かかります(JDBCと比較して:7秒)。私はバッチ執筆を助けるべきであることを読んだ - しかしない!データを挿入するとEclipseLinkが非常に遅くなる
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();
そして最後に、私のEclipseLink構成:私が間違ってやっている何
<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>
@Entity
public class TestRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public int test;
}
コードは、レコードを挿入するには?私はいくつかの設定を試みましたが、何も助けに見えません。 私に手伝ってくれてありがとう! :)
-Stefan
もう一つは、コネクターが使用するデータのURLに?rewriteBatchedStatements=true
を追加することです。
これは約120300の挿入を約30秒まで実行したが、これは約60秒前であった。
ありがとう!今は約9秒かかります。うまくいけばうまくいくはずです。 – Stefan