User has only one method to use, he must be able to save any kind of collection with one method from frontend:
save(Collection<foo> bar)
I am using the latest Hibernate with annotations.
How can I implement the backend for this? Basically I need it to understand, what objects are inside Collection.
Problem is that, I don’t want to create a save method for every table in my DB, wanna do it generic. Or if this is not possible, some other ideas, what logic to use?
You can implement generic method that saves collection in such way.
Create abstract generic DAO class:
Concrete implementation of DAO for some entity:
Class<T> clazzis necessary for implementing finders so you can skip this if you don’t need them. In such case you can write only one generic class (not abstract class and subclasses for each entities).Here is very good article about creation generic DAO with Hibernate and JPA.