I need no access spring service-layer from ejb. Inside spring I use "Open Session In View" (OSIV) pattern to access hibernate session in web views for lazy loading properties. How can I use OSIV pattern in EJB container?
My current solution is not so good:
in ejb-support class:Code:public interface AbstractCallback { Object execute(); } public class OSIVTemplate { private SessionFactory sessionFactory; protected void addInterceptor(){ // ... // add hibernate interceptor // ... } protected void removeInterceptor(){ // ... // remove hibernate interceptor //... } public final Object doInOSIV(AbstractCallback callback){ addInterceptor(); Object result = callback.execute(); removeInterceptor(); return result; } }
May be there is simpler way to put interceptors on EJB...Code:public class OrderService extends org.springframework.ejb.support.AbstractStatelessSessionBean { private OSIVTemplate template; public Order getOrderById(final long id){ final OrderService orderService = (OrderService) getBeanFactory().getBean("orderService"); Order order = (Order) template.doInOSIV(new AbstractCallback(){ public Object execute() { return orderService.getOrderById(id); } }); return order; } protected void onEjbCreate() throws CreateException { // TODO Auto-generated method stub } }


Reply With Quote