Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:00:38+00:00 2026-06-09T15:00:38+00:00

User has only one method to use, he must be able to save any

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:00:40+00:00Added an answer on June 9, 2026 at 3:00 pm

    You can implement generic method that saves collection in such way.

    Create abstract generic DAO class:

    public abstract class AbstractHibernateDAO<T> {
    
        private final Class<T> clazz;
    
        @Autowired
        private SessionFactory sessionFactory;
    
        public AbstractHibernateDAO(Class<T> clazz) {
            this.clazz = clazz;
        }
    
        public void saveCollection(Collection<T> entities) {
            for (T t: entities) {
                sessionFactory.getCurrentSession().save(t);
            }
        }
    
        // Other CRUD methods.
    
    }
    

    Concrete implementation of DAO for some entity:

    @Repository
    @Transactional
    public class TestEntityHibernateDAO extends AbstractHibernateDAO<TestEntity> {
    
        public TestEntityHibernateDAO() {
            super(TestEntity.class);
        }
    
    }
    

    Class<T> clazz is 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A user has a list of books, but only 1 book can be displayed
Possible Duplicate: Tasks should show up only if the user has been assigned it
I need to do some processing only after the user has successfully logged in
UPDATE: I've realized that the below problem only occurs if the user has already
A user has sent me some information that they posted to one of my
In my community, every user should only have one account. So I need a
User has many Tracks, through Favorite. Favorite has some extra per-user meta-data about the
the user has the option of dragging several pictureboxes around the form. when he
THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and
a post has a user (belongsTo) and a user has a profile (hasOne). Normally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.