views:

35

answers:

2

I'm working on a utility to update a list of entities in a database as a group. The database contains a list of entities. The result of the update is a new list. The API accepts this new list.

The update may end up modifying some of the entities in the list, creating new ones and deleting some. So at the entity level, I may have to do any of an insert, delete or update operation. But it's always true that the final list in the database will be the same as the list passed down to the API.

Is there in Hibernate a way to treat this operation at the list level, that is, tell Hibernate to persist this list of entities, and let it take care of which need to be created, updated or deleted?

There is no entity/table representing this list, btw. Just the entities themselves in a table.

A: 

I don't think that you will find a process(List<Entity>) method in Hibernate if this is your question. Actually, while I can think of some custom implementations, what you are trying to do is not totally clear. For example, I didn't get from where the entities in the list come from? And how would hibernate decide that an entity should be deleted? Could you clarify these points?

Without answers to these question, I can only suggest to have a look at The StatelessSession interface and/or DML-style operations in the documentation. Maybe you'll find some inspiration in there.

Pascal Thivent
A: 

It sounds like you're wanting to do a batch update. This page has the particulars for Hibernate.

Granger44