1

The hibernate session has load method for retrieving a proxy without loading entire object, this is often uses when it is need to link parent and child entity. But what about updating proxy? For example:

 MyEntity entity = session.load(MyEntity.class, 1l);
 entity.setName("newName");
 session.saveOrUpdate(entity);

It is expected here that only name column will be updated for entity with id=1l without loading entire entity. Is it true? Does this piece of code equals to sql execution like UPDATE MyEntity SET name = 'newName' where id = 1 or not?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Cherry
  • 31,309
  • 66
  • 224
  • 364

1 Answers1

1

No, this is no equals by default. But it's possible to do it with Hibernate and it's called dynamic update. You can enable it via DynamicUpdate annotation or via property of the Entity annotation(note: it's deprecated)

But in both cases, there are some limitations, like the one, that you have to fetch your entity first.

You can find a number of examples over internet, here is one of them. And here is one related article and one more SO question about perfomance of dynamic updates.

Community
  • 1
  • 1
Stanislav
  • 27,441
  • 9
  • 87
  • 82