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

  • Home
  • SEARCH
  • 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 714221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:03:03+00:00 2026-05-14T05:03:03+00:00

Hello everyone here is my DAO class : public class UsersDAO extends HibernateDaoSupport {

  • 0

Hello everyone here is my DAO class :

public class UsersDAO extends HibernateDaoSupport {

    private static final Log log = LogFactory.getLog(UsersDAO.class);

    protected void initDao() {
        //do nothing
    }

    public void save(User transientInstance) {
        log.debug("saving Users instance");
        try {
            getHibernateTemplate().saveOrUpdate(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

public void update(User transientInstance) {
        log.debug("updating User instance");
        try {
            getHibernateTemplate().update(transientInstance);
            log.debug("update successful");
        } catch (RuntimeException re) {
            log.error("update failed", re);
            throw re;
        }
    }

    public void delete(User persistentInstance) {
        log.debug("deleting Users instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public User findById( java.lang.Integer id) {
        log.debug("getting Users instance with id: " + id);
        try {
            User instance = (User) getHibernateTemplate()
                    .get("project.hibernate.Users", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

}

Now I wrote a test class(not a junit test) to test is everything working, my user has these fields in the database : userID which is 5characters long string and unique/primary key, and fields such as address, dob etc(total 15 columns in database table). Now in my test class I intanciated User added the values like :

User user = new User;
user.setAddress("some address");

and so I did for all 15 fields, than at the end of assigning data to User object I called in DAO to save that to database UsersDao.save(user); and save works just perfectly. My question is how do I update/delete users using the same logic?

Fox example I tried this(to delete user from table users):

User user = new User;
user.setUserID("1s54f"); // which is unique key for users no two keys are the same
UsersDao.delete(user); 

I wanted to delete user with this key but its obviously different can someone explain please how to do these. thank you

UPDATE :

Do I need to set all 15 fields on User object to delete it like I did with save method ?

  • 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-05-14T05:03:03+00:00Added an answer on May 14, 2026 at 5:03 am

    Having not looked at Hibernate for quite a while now, I can only hazard a guess at the problem.

    It seems that you are creating a User object, but only populating the User ID field, so the persistence layer knows nothing about the actual User.

    I would recommend using a retrieve function that can find the User with the given ID, and then pass that User into the delete method.

    User u = UsersDao.findById("1s54f");
    UsersDao.delete(u);
    

    This should work, as the persistence layer will know about the User, so it has all of the details it needs to perform the delete.

    However, a more efficient method would be to find a way of deleting a user by ID, so you do not have to query the database to get the instance of the User and then delete it.

    Hope this helps.

    Chris

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

Sidebar

Related Questions

First question here so hello everyone. The requirement I'm working on is a small
Hello everyone I have error which breaks up my build for no reason, here
Hello everyone it is me again with another question. The booking system located here
enter code here hello, everyone, can somebody explain what is my problem in this
Hello can anybody solve this please I'm creating the object in the action class
Hello everyone I been trying get php uploader working but having a lot of
Hello everyone I'm trying to improve my Java skills by solving some problems from
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Introduction : Hello Everyone, I have been looking for days for a way to
Some details XAMPP 1.7.1 OS tested on vista and xp Hello everyone. I have

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.