Retrieving an entity via the getReference method doesn’t involve any database access. If one or more fields (excluding the ID field) are updated and then persist is invoked, will Hibernate retrieve the entity from the database before persisting it? Or does it persist the updated fields with just one SQL query, leaving the other fields unchanged?
Code example:
User user = entityManager.getReference(User.class, id);
user.setUsername(username);
entityManager.persist(user);