Hibernate标准加载对象,对象会持久化吗?
Hibernate criteria loading object, will the object become persistent?
Criteria crit = sess.createCriteria(Cat.class);
crit.setMaxResults(50);
List cats = crit.list();
cats
是否会成为当前会话中的持久对象sess
?
我检查了 API,但它没有提及任何内容。我很担心这个,所以我希望我能找到某个地方正式提到对象是否会持久化,当我第一次使用 Hibernate 的 session
加载对象时,我不知道对象会变成持久化的,并且我不小心修改了对象内部的值,更改刷新到数据库,这给我带来了很大的问题。
基于此https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html、
The interface org.hibernate.Criteria represents a query against a
particular persistent class.
是否意味着返回的对象是持久的?我可以安全地更改对象内部的值吗?
如果对象不会持久化,为什么 API 文档有一个 setReadOnly
属性来控制:
Set the read-only/modifiable mode for entities and proxies loaded by
this Criteria. This setting overrides the default setting for the
persistence context.
上面这个我很迷茫!
它将在当前会话中持久化。如果您更改对象值并刷新,它将在事务结束时保存到数据库中。检查 https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/objectstate.html 段 10.4.1。执行查询:
A query is usually executed by invoking list(). The result of the
query will be loaded completely into a collection in memory. Entity
instances retrieved by a query are in a persistent state.
Criteria crit = sess.createCriteria(Cat.class);
crit.setMaxResults(50);
List cats = crit.list();
cats
是否会成为当前会话中的持久对象sess
?
我检查了 API,但它没有提及任何内容。我很担心这个,所以我希望我能找到某个地方正式提到对象是否会持久化,当我第一次使用 Hibernate 的 session
加载对象时,我不知道对象会变成持久化的,并且我不小心修改了对象内部的值,更改刷新到数据库,这给我带来了很大的问题。
基于此https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html、
The interface org.hibernate.Criteria represents a query against a particular persistent class.
是否意味着返回的对象是持久的?我可以安全地更改对象内部的值吗?
如果对象不会持久化,为什么 API 文档有一个 setReadOnly
属性来控制:
Set the read-only/modifiable mode for entities and proxies loaded by this Criteria. This setting overrides the default setting for the persistence context.
上面这个我很迷茫!
它将在当前会话中持久化。如果您更改对象值并刷新,它将在事务结束时保存到数据库中。检查 https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/objectstate.html 段 10.4.1。执行查询:
A query is usually executed by invoking list(). The result of the query will be loaded completely into a collection in memory. Entity instances retrieved by a query are in a persistent state.