user3420018
user3420018

Reputation: 25

JPA: Bulk Insert records into element collection

Is there a way to bulk insert values into a List element collection?

This is a sample of the entity:

    public Class File{
     private String name;
     @ElementCollection
     @CollectionTable(name="file_tags")
     private List<String> tags = new ArrayList<>();
      .....
    }

I Need to add a list of tags to a large number of files (hundred of thousands)... That's why I am looking for a way to do it in a bulk insert... I searched with no result till now.

Note that I am using eclipselink as JPA provider.

Upvotes: 0

Views: 372

Answers (2)

CodeScale
CodeScale

Reputation: 3334

you have to enable batch writing by adding these 2 properties inside your persistence.xml

 <!-- Enable batch writing -->
 <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
 <!-- Batch size -->
 <property name="eclipselink.jdbc.batch-writing.size" value="100"/>

Upvotes: 3

tm_user
tm_user

Reputation: 3

Is it with reference to List that you are looking for the bulk insert of JPA? For eclipse link JPA you can use the batch insert for bulk insertion, in case you have sequences it might take time.

Upvotes: 0

Related Questions