java - How to use single sessionFactory for hibernate Intercepter -


I'm experimenting with the hibernate interceptor (Hibernate 4.x). I want to do some operations to save the method of session. So I have the following methods:

  onSave () // When the saved operation is preformed   

Problem: In postFlush () I want to work to save. So my control got stuck in the loop because when my session was being called, the EmptyInterceptor's onSave () and postFlush () method was called to block the saved operation.

To overcome this problem, I used two session factories for 1 session operation (save, update etc.) and 2 for hibernate intritor

but I am concerned that How can I exercise this problem with a session session ??

Public class audiologic interceptor provided an empty interceptor {

  public boolean onSave (Object unit, serialable id, object [] state, string [] property name, type [ ] Type) {return false; } // is committed after the database is committed to the public Zero Postflush (Iterator Itater) / / / here with the session. I want to save with the session. This loop session comes in tempSession = HibernateUtil.hibernateTemplateLog .getSessionFactory (). OpenSession (); Try {item item = new item (); Item.setName ("anyItem"); Item.setValue ("anyValue"); TempSession.save (item); TempSession.flush (); } Finally {tempSession.close (); }}}    

You do not use interceptors to save objects. You use it to modify / format items, and session objects rest for you, but do not add new items

If you actually have a flush () or at the end of the commit () If you want to add a line, then you use Spring-AOP as a single option. There you can add advice to the hibernate services, so, you can save something immediately after running any method.

Work around I thought that's the following.

  public zero post flush {for (; iterator.hasNext ();) {if (! (Iterator.next (for example)) // // < & Lt; & Lt; & Lt; & Lt; If you are saving items or other objects, then you verify that you leave this block while saving the item. Session tempSession = HibernateUtilit Hibernate template log .getSessionFactory (). OpenSession (); Try {item item = new item (); Item.setName ("anyItem"); Item.setValue ("anyValue"); TempSession.save (item); TempSession.flush (); } Finally {tempSession.close (); }}}}}    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -