P
P
palebluedot2011-11-16 16:07:01
Hibernate
palebluedot, 2011-11-16 16:07:01

Spring 3 MVC + Hibernate. Data editing?

Hello.
I tried to make my web application using this article. But when I decided to attach data editing to it, I got stuck. My problem is similar to this one . Can anyone give a simple example with data editing? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
swinntus, 2013-11-14
@swinntus

The easiest method in this case is to use Query Update. Something like: "UPDATE User u SET u.name=:name where u.id = :id" In this case, changes the content of one field (name in the example) according to the existing field (id). But as for me it is more convenient to use not the SessionFactory, but the EntityManager, then the code in the repository will be like this:

  @PersistenceContext
  private EntityManager entityManager;

  public void updateUser(User user) {
    entityManager.merge(user);
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question