The plan for this article is in line with my requirements and is documented here:
To trigger a scenario, a solution:
1. Show business operations, open a session to identify some entities, when an entity is a persistent object that exists in the session. Use this entity for page presentation through business logic. This session is not closed at this time.
2. Then execute the Save business logic and pass the entity ID obtained in the previous step back to the background. A temporary object is created by new, and I assign the ID returned as the primary key to the temporary object. The Session.save (obj) is then called; Method... Throws an exception.
The reason is simple, there are 2 OID objects in the session, and Hibernate does not know which one to persist into the library. At that time the solution is also clear, direct clear (); Clear the session cache is not OK. but the clear hit surface is too wide (use with caution!) ). Other "innocent" objects have also been killed, causing other businesses to fail.
later, a evict method was found in the session, the "fixed-point Cleanup" object cache. This is good, first with the return of the ID used in fact here with the Load method is still loaded from the cache anyway, get the persistent entity in the session, then kill, and then save the temporary entity. No problem.
Original address: http://www.cnblogs.com/linjiqin/p/3531374.html
Since my session is encapsulated and there is no get,evict method in itself, the session that was encapsulated by him is called first, and then the two methods can be used.
Hbsession sess = Hbutil.gethbsession ();
Query Queryuser = Sess.createquery (from User where name=:name);
Queryuser.setstring ("name", "testers");
List<user> userlist = Queryuser.list ();
...
...
...//Here is the process of using
The next cleanup
for (int i=0;i<userlist.size (); i++) {
Sess.getsession () is to get the encapsulated session because my sess itself does not have get (xxxx,xxx), evict (Object) method
How to use your own Baidu Session.get method
Object tempuser= sess.getsession (). get (User.class, Userlist.get (i). GetKey ());
Remove the object from the Sess cache
Sess.getsession (). evict (tempuser);
}
A different object with the same identifier value is already associated with the session