[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep
jtonic
do-not-reply at jboss.com
Wed Nov 28 16:06:26 EST 2007
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=bb&op=viewtopic&p=4108681#4108681
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108681
More information about the jboss-user
mailing list