Criteria crit = sess.createCriteria(Cat.class);
crit.setMaxResults(50);
List cats = crit.list();
Will the cats
become persistent object in the current session sess
?
I checked the API, but it doesn't mention anything. I very worry this, so I hope I can find somewhere officially mention whether the objects will be persistent or not, when I first time using Hibernate's session
to load the object, I wasn't aware the object become persistent, and I accidentally amend the value inside the object, the changes flush to database, which cause very big problem for me.
Based on this 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.
Does it mean the object returned is persistent? Can I safely change the value inside the object?
If the object will not be persistent, why the API doc having a setReadOnly
attribute to control:
Set the read-only/modifiable mode for entities and proxies loaded by this Criteria. This setting overrides the default setting for the persistence context.
I am very confused above this!