1

Is it possible to use an annotation to do whatever OpenSessionInView filter does: to keep hibernate session open in scope but for only one annotated function?

PS I would need this for local fixes in some legacy code.

MS13
  • 327
  • 5
  • 16
  • if you use spring you can do this with spring aop or use java proxy for open session , or you can use aspectj – xyz Jun 21 '17 at 09:04
  • I hope I won't need this but just in case I can't find something better: how? – MS13 Jun 21 '17 at 11:34
  • what do you use except java , hibernate ? spring ? – xyz Jun 21 '17 at 11:38
  • all of them yes – MS13 Jun 21 '17 at 11:41
  • https://stackoverflow.com/questions/32934397/configuring-hibernate-session-with-spring-aop?answertab=oldest#tab-top – xyz Jun 21 '17 at 11:44
  • First thing that this is the looong path, of (re)building parts of hibernate which I try to avoid. secondly you showed how to create a pointcut (I already know that) but the main problem is what do I call afterwards? how do I keep session open and avoid closing it when not needed. So ... – MS13 Jun 21 '17 at 12:00
  • You have session till you have transaction. Use it. Aspect is the shortest way if you what small changes for your source code – xyz Jun 21 '17 at 12:03
  • Also did you see this http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/orm/hibernate4/support/OpenSessionInterceptor.html – xyz Jun 21 '17 at 12:05

0 Answers0