Why load() works in the same way that get() in Hibernate?

Viewed 68

I'm trying to update a entity field in this way:

    SessionFactory factory = HibernateUtil.getSessionFactory();
    Session session = factory.openSession();
    session.beginTransaction();
    User user = session.load(User.class, 4);
    user.setName("Bober11");
    session.getTransaction().commit();
    session.close();

I was thinking that in this case Hibernate will update the row in the table without hitting it (I mean, without select), however, I saw in the console that Hibernate is doing a select:

Hibernate: select user0_.id as id1_1_0_, user0_.email as email2_1_0_, user0_.name as name3_1_0_, user0_.phone as phone4_1_0_ from User user0_ where user0_.id=?
Hibernate: update User set email=?, name=?, phone=? where id=?

I.e. it looks like if I was using get().

Why this's happening? Is it possible to update and insert without selecting? and without using direct sql query statements.

2 Answers
Related