Reputation: 7041
I am trying to override org.apache.tapestry5.hibernate.HibernateSessionManager
. To do this I added this to my AppModule:
public static void contributeServiceOverride(
MappedConfiguration<Class<?>, Object> configuration)
{
configuration.addInstance(HibernateSessionManager.class,
HibernateSessionManagerOverride.class);
}
The content of HibernateSessionManagerOverride
(for the time being) is the same as the default Tapestry implementation org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl
.
When I run my application I get this error:
java.lang.RuntimeException:
Exception constructing service 'ServletApplicationInitializer':
Unable to instantiate class org.apache.tapestry5.services.TapestryModule as a module:
Exception constructing service 'ServiceOverride':
Error invoking service contribution method com.company.services.AppModule.contributeServiceOverride(MappedConfiguration):
Exception constructing service 'ServiceOverride':
Construction of service 'ServiceOverride' has failed due to recursion:
the service depends on itself in some way. Please check org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at ServiceOverrideImpl.java:31) via org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder) (at TapestryIOCModule.java:49) for references to another service that is itself dependent on service 'ServiceOverride'.
Upvotes: 0
Views: 523
Reputation: 1358
I dont want to devalue Lance's answer but using this method I found that ThreadCleanupListener was not added or called which means that sessions were not being rolled back at the end of the threads lifecycle. I modified the above example to add the override as a threadcleanup listener.
public static HibernateSessionManager decorateHibernateSessionManager(
HibernateSessionManager defaultManager,
@Autobuild HibernateSessionManagerOverride overrideManager,
PerthreadManager perthreadManager)
{
perthreadManager.addThreadCleanupListener(overrideManager);
return overrideManager;
}
this is critical so that sessions are rolled back and closed after use.
Upvotes: 0
Reputation: 27994
Looking at hibernateModule.java, I can see the following:
@Contribute(ServiceOverride.class)
public static void provideInjectableSessionObject(
MappedConfiguration<Class, Object> configuration,
@HibernateCore Session session)
{
configuration.add(Session.class, session);
}
Perhaps this is causing the circular dependency?
You might need to use a decorator instead of a ServiceOverride
eg:
public static HibernateSessionManager decorateHibernateSessionManager(
HibernateSessionManager defaultManager,
@Autobuild HibernateSessionManagerOverride overrideManager)
{
return overrideManager;
}
Upvotes: 1