java - persist/update collection of data into database using hibernate -
i newbie hibernate framework , curious way persist , update work.
currently in project when persist or update collection of data database, doing 1 one via looping method. instance,
public persistdata(){ list<person> personlist = new arraylist<>(); for(person person : personlist){ session.persist(person); } }
is possible to, example,
session.persist(personlist);
or there anyway else can persist/update collection of data @ once without looping?
editted: have found hibernate batch processing in how insert multiple rows database using hibernate? , best way insert amount of records in hibernate
i developing generic class persist/update/delete data hibernate, should provide method with
public void (list<t> addeditemlist)
or
public void (t addeditem)
for understanding, bulk persist should done large amount of transactions right? if times there 1 or 2 objects persisted, batch processing still appropriate?
the main point here begin transaction, persist all, , commit. try not using @transaction since doing code.
entitymanager em = entitymanagerprovider.get(); // em.clear();//remove if caching necessary em.gettransaction().begin(); for(buildings b:buildingsarray) { em.persist(b); } em.gettransaction().commit();
Comments
Post a Comment