2

I have a data model that has a ONE TO MANY relationship between ONE entity and 11 other entities. These 12 entities together represent one data packet. The problem I am having is to do with the number of inserts that occur on the 'many' side of these relationships. Some of them can have as many as 100 individual values so to save one whole data packet in the database it requires up to 500 inserts.

I am using MySQL 5.5 with InnoDB tables. Now, from testing the database I see that it can easily do 15000 inserts per second when processing a batch insert (and even more with LOAD DATA, but that's not practical for this case).

Is there some way to bunch up these individual 500 inserts into, say - 5 inserts with 100 VALUES (for the 5 linked entities that each has 100 values) using Hibernate?

As Requested:

@OneToMany(mappedBy="beat", cascade=CascadeType.ALL)
@OrderBy("miliseconds ASC")
public List<AmbientLight> lights;

I should probably also mention one important piece of information - I am using Play! Framework 1.2.3

4

2 に答える 2

3

挿入の「グループ」ごとに Hibernate Sessions を使用することで、この問題を解決することができました。その結果、データの保存に必要な時間が約 7 分の 1 に短縮されました。以前は、1 つの「パケット」を保存するのに約 2000 ミリ秒かかっていましたが、現在は同じことを行うのに 200 ミリ秒から 300 ミリ秒かかります。

繰り返しますが、これはPlayに有効です。Framework 1.2.3 - これが Hibernate を利用する他のフレームワークやアプリケーションに適用されるかどうか、またはどのように適用されるかはわかりません。

    Session mySession = (Session) Pressure.em().getDelegate();

    for(int i = 0 ; i < data.size() ; i++){
        initializeFromJsonAndSave(data.get(i), mySession);
    }
    s.flush();
    s.clear();

オブジェクトのsave()メソッドを呼び出す代わりに、 mySession.save(myNewObject)を呼び出すように「initializeFromJsonAndSave」メソッドが変更されました。

于 2013-07-26T10:54:35.943 に答える
1

この件に関する2つの良い答えがあります

ID ジェネレーター (再生でデフォルトで使用されるジェネレーター) では、バッチ挿入が無効になっていることに注意してください。

于 2013-07-25T07:43:30.140 に答える