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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:59:06+00:00 2026-06-15T06:59:06+00:00

I have a database (in postgres) and I’m working with spring 3 and hibernate

  • 0

I have a database (in postgres) and I’m working with spring 3 and hibernate 3, the problem is when try to delete or get a row from database, here is the class that I’m using, ohh another thing after the query, a don’t have any mistake, the only thing es that class User is null

@Repository("userDao")
public class UserDao implements IUserDao {

    @Autowired
    private SessionFactory sessionFactory;

    public void SaveUser(User user) {
    sessionFactory.getCurrentSession().save(user);
    }
    @SuppressWarnings("unchecked")
    public List<User> ListUsers() {
        List<User> users = (List<User>) sessionFactory.getCurrentSession().createCriteria(User.class).list();
        return users;
    }
    public User GetUserById(Integer id) {               
        User user = (User) sessionFactory.getCurrentSession().load(User.class, id);
        return user;
    }
}

by the way, methods, SaveUser and ListUser work really good.

this is the model class

@Entity
@Table(name = "mrbean")
public class User {

@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@Column (name = "id")
private Integer id;

@NotNull (message = "not null")
@NotEmpty (message = "empty")
@Column (name = "user_name", length = 20, nullable = false, unique = true)
private String userName;

@NotNull 
@NotEmpty (message = "empty password")
@Size (min = 7, max = 20, message = "La contraseña debe tener entre 7 y 20 caracteres")
@Column (name = "password", length = 20, nullable = false)
private String password;

//with getters and setters

this is what hibernate show in console when
User user = (User)sessionFactory.getCurrentSession().load(User.class, id) is executed

Hibernate: select user0_.id as id0_0_, user0_.password as password0_0_, user0_.user_name as user3_0_0_ from mrbean user0_ where user0_.id=?

  • 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-15T06:59:08+00:00Added an answer on June 15, 2026 at 6:59 am

    I would use “get” instead of “load” because load() creates a proxy of User (see Hibernate ref doc )
    so i would try : User user = (User) sessionFactory.getCurrentSession().get(User.class, id);

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

Sidebar

Related Questions

I have a problem with doctrine2 in symfony2 app with postgres database. I get
Is it possible to have the postgres database dump(pg_dump) using SQLAlchemy? i can get
I am using a hibernate application to store data in Postgres database I have
I have a postgres database with stored images 'bytea' type and I try to
I have a script which outputs some data from a postgres database: #!/bin/bash dbname=inventory
I have a postgres database and I want to generate the entity class of
I have an SQL file generated from a Postgres database that I want to
I have a postgres database on my localhost I can access without a password
I have a postgres database that I want to know some quick stats. For
Possible Duplicate: How to empty DB in heroku I have a Postgres database on

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.