[jboss-user] [JBoss AOP] - Re: Catching LazyInitialization exception within an Intercep

mlouna do-not-reply at jboss.com
Wed Nov 28 10:55:13 EST 2007


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=4108544#4108544

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108544



More information about the jboss-user mailing list