[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep
anonymous wrote : However in the general case where I have no knowledge of my object's getters/setters methods name, it is getting a bit more complicated. You are very right. I'm working also for a LIE solution, but I use some hibernate stuff. I have also the same problem that U've mentioned. IMHO reflection is the solution. The following are the hibernate methods that help me doing the LIE interceptor: Hibernate.isInitialized(object); Hibernate.initialize(object); session.lock(object, LockType); Regards, jtonic mlouna wrote : You're absolutely right. | | I can cast the following to a set of Objects | | SetObject mySet = (SetObject)methodInvocation.getCalledMethod().invoke(methodInvocation.getTargetObject(), methodInvocation.getArguments()); | | | and then loop through it with | | Iterator iter = mySet.iterator(); | | In the particular cases where I know my object type I can call | parent.getChildren().getChildName() and indeed catch the thrown Lazy Init Exception | | However in the general case where I have no knowledge of my object's getters/setters methods name, it is getting a bit more complicated. | | Will have to think of method refelction solution. | View the original post : http://www.jboss.com/index.html?module=bbop=viewtopicp=4109378#4109378 Reply to the post : http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4109378 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep
You're absolutely right. I can cast the following to a set of Objects SetObject mySet = (SetObject)methodInvocation.getCalledMethod().invoke(methodInvocation.getTargetObject(), methodInvocation.getArguments()); | and then loop through it with Iterator iter = mySet.iterator(); In the particular cases where I know my object type I can call parent.getChildren().getChildName() and indeed catch the thrown Lazy Init Exception However in the general case where I have no knowledge of my object's getters/setters methods name, it is getting a bit more complicated. Will have to think of method refelction solution. View the original post : http://www.jboss.com/index.html?module=bbop=viewtopicp=4109173#4109173 Reply to the post : http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4109173 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep
Here's the full code: public Object invoke(Invocation invocation) throws Throwable { InitialContext initCtx = new InitialContext(); EntityManagerFactory emf = (EntityManagerFactory)initCtx.lookup(java:/EntManager1Factory); EntityManager em = emf.createEntityManager(); MethodCalledByMethodInvocation methodInvocation = (MethodCalledByMethodInvocation)invocation; try { methodInvocation.getCalledMethod().invoke(methodInvocation.getTargetObject(), methodInvocation.getArguments()); } catch (LazyInitializationException ex) { Object tmpEntity = em.merge(methodInvocation.getTargetObject()); methodInvocation.setTargetObject((methodInvocation.getTargetObject().getClass().cast(tmpEntity))) } return methodInvocation.invokeNext(); } View the original post : http://www.jboss.com/index.html?module=bbop=viewtopicp=4108544#4108544 Reply to the post : http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4108544 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep
IMO getXXX() invocation does't throw LIE on lazy collection. It return an unitialized PersistenceCollection. If you trie to invoke a collection method on it get an LIE. Ex.: Collection children = parent.getChildren(); // doesn't throw LIE col.iterator(); //throws LIE Regards, jtonic. mlouna wrote : Here's the full code: | | public Object invoke(Invocation invocation) throws Throwable { | | InitialContext initCtx = new InitialContext(); | EntityManagerFactory emf = (EntityManagerFactory)initCtx.lookup(java:/EntManager1Factory); | EntityManager em = emf.createEntityManager(); | | MethodCalledByMethodInvocation methodInvocation = (MethodCalledByMethodInvocation)invocation; | | try { | methodInvocation.getCalledMethod().invoke(methodInvocation.getTargetObject(), methodInvocation.getArguments()); | } catch (LazyInitializationException ex) { | Object tmpEntity = em.merge(methodInvocation.getTargetObject()); | methodInvocation.setTargetObject((methodInvocation.getTargetObject().getClass().cast(tmpEntity))) | } | | return methodInvocation.invokeNext(); | | } | View the original post : http://www.jboss.com/index.html?module=bbop=viewtopicp=4108681#4108681 Reply to the post : http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4108681 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user