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 7784531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:06:35+00:00 2026-06-01T20:06:35+00:00

I am creating a web application that lets the user store and retrieve information

  • 0

I am creating a web application that lets the user store and retrieve information from a DB through a GUI using spring and hibernate.

I have gotten stuck when it comes to creating the DAO and service layer. I want to create a method that can add a new delivery. In my delivery table i have Product Id and Customer Id which both are mapped to their own tables that contain Product Name, Product Type and Customer Name, Customer Country respectively.

The part that I have trouble with is that I want the end user to record a delivery by entering the product type, product name, customer name, customer country and date. Do I,

(1) Create a DAO with a method for adding a new delivery that includes these objects

or

(2) Create a DAO that just persist a general object to the DB and then use a service method to implement the DAO for each separate object?

Thank you for your help!

/D

  • 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-01T20:06:36+00:00Added an answer on June 1, 2026 at 8:06 pm

    here is a snippet of my generic dao, which I inject into each service layer class.

    @Component("Dao")
    public class Dao implements IDao  {
        @Resource(name = "sessionFactory")
        private SessionFactory sessionFactory;
    
        @Override
        public <T> T save(final T o){
            return (T) sessionFactory.getCurrentSession().save(o);
        }
    
        @Override
        public void delete(final Object object) {
            sessionFactory.getCurrentSession().delete(object);
        }
    
        @Override
        public <T> T get(final Class<T> type, final Long id) {
            return (T) sessionFactory.getCurrentSession().get(type, id);
        }
    
        @Override
        public <T> List<T> getFieldsEq(final Class<T> type, final Map<String, Object> restrictions) {
            final Session session = sessionFactory.getCurrentSession();
            final Criteria crit = session.createCriteria(type);
            for (Map.Entry<String, Object> entry : restrictions.entrySet()) {
                crit.add(Restrictions.eq(entry.getKey(), entry.getValue()));
            }
    
            return crit.list();
        }
    }
    

    Which can hen be used in your service layer like so :

    @Transactional(readOnly = true)
    public List<City> getCities() {
      return dao.getAll(City.class);
    }
    

    And of course you could extend the dao for specific complex queries. Having one generic dao obeys single point of responsibility principle, DRY, and makes it easier to test. The transactions should be on serivce layer and directly relate to units of work.

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

Sidebar

Related Questions

I am interested in creating a simple web application that will take in user
When creating a web application, and lets say you have a User object denoting
I'm creating a web application that allows users to make changes through Javascript. There
I am creating a web-application which lets you select a template from the template
I am creating a web application that asks user for randomized security question. However,
I am creating a web application that is going to send messages using NServiceBus,
I am Creating a web application that will get homework from schools website. I
I'm creating a web application that uploads websites from my server to youtube on
I am creating a web application that is accessing a SQLite database in the
I am thinking of creating a web application that shows a map of a

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.