Do I have to refresh entities after bulk updates / deletes with HQL?

前端 未结 1 648
情深已故
情深已故 2021-01-23 14:05

I have written some DAO methods that do bulk updates / deletes with HQL but I see that when the query is executed the entities in memory are not sychronized (the cache is not up

1条回答
  •  温柔的废话
    2021-01-23 14:28

    The answer is NO. As documented here:

    13.3. DML-style operations

    cite:

    ...As already discussed, automatic and transparent object/relational mapping is concerned with the management of object state. This implies that the object state is available in memory, hence manipulating (using the SQL Data Manipulation Language (DML) statements: INSERT, UPDATE, DELETE) data directly in the database will not affect in-memory state. However, NHibernate provides methods for bulk SQL-style DML statement execution which are performed through the Hibernate Query Language (HQL)...

    DML is there for us, to skip the state management in memory...being more efficient from SQL statements point of view. But that means:

    manipulating ... data directly in the database will not affect in-memory state

    0 讨论(0)
提交回复
热议问题