[jboss-user] [EJB 3.0] New message: "I'm having a hard time with this error "org.hibernate.LazyInitializationException: failed to lazily initialize""

Flemming Harms do-not-reply at jboss.com
Mon Mar 15 04:39:28 EDT 2010


User development,

A new message was posted in the thread "I'm having a hard time with this error "org.hibernate.LazyInitializationException: failed to lazily initialize"":

http://community.jboss.org/message/531925#531925

Author  : Flemming Harms
Profile : http://community.jboss.org/people/fharms

Message:
--------------------------------------------------------------
I'm having a hard time with this error "org.hibernate.LazyInitializationException: failed to lazily initialize". I know the reason for this error but in my case it should not happen because all database transactions are happen in the same scope. (Well thats what I at least thought it did). But I can see the session is flushed because the transaction is committed inside the scope.
 
I have a problem understanding why transactions are committed between calls of two local pojo's when I use "TransactionAttributeType.REQUIRED". I have pojo A which have a Session injected and when it starts, a number of changes happen and objects are created which is attached to the Hibernate session. In the same scope Pojo B is called which is looked up through JNDI, the session from A is passed into method on pojo B as parameter.  Pojo B also make changes and create a number of objects which is attach to the Hibernate session. When Pojo B return from it method the transaction is commited and the session is flushed. All the objects which was created is now detached and when Pojo C is referring to any of the object it throw an "LazyInitializationException". In my mind should first be committed when the Pojo A start method is done and the session is flushed and closed 
 
 Please advise what I'm doing wrong and I how can I make sure it run in the same transaction so the session is not flushed.
 
br
Flemming

@Service(PojoA.....)
@Management(.....)
Public class PojoA implements ..... {
 
@PersistencyContext
org.hibernate.session session;
 
public bootstrap() {
    session.save(....);
}
 
@TransactionAttribute(TransactionAttributeType.REQUIRED)
 public start() {
   bootstrap();
   pojob.bootstrap(session);
   pojoc.bootstrap(session);
}
}
 
@Local(.....class)
 @LocalBinding(jndiBinding=".....")
@Service(PojoB.....)
 @Management(.....)
Public class PojoB implements ..... {
 
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public bootstrap(org.hibernate.session session) {
     //do some database work
     session.save(.....);
   }
}
 
@Local(.....class)
 @LocalBinding(jndiBinding=".....")
@Service(PojoC.....)
 @Management(.....)
 Public class PojoC implements ..... {
 
   @TransactionAttribute(TransactionAttributeType.REQUIRED)
   public bootstrap(org.hibernate.session session) {
      //do some database work
      session.save(.....);
   }
 }
 
Thread [main] (Suspended)    
     SmaCoreSystemInitializeHook.initializing(ServerServiceLocator) line: 99    
     NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]    
     NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39    
     DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25    
     Method.invoke(Object, Object...) line: 597    
     StatefulContainerInvocation(MethodInvocation).invokeTarget() line: 122    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 111    
     EJBContainerInvocationWrapper<A,T>.invokeNext() line: 69    
     InterceptorSequencer.invoke(Invocation) line: 73    
     InterceptorSequencer.aroundInvoke(Invocation) line: 59    
     GeneratedMethodAccessor280.invoke(Object, Object[]) line: not available    
     DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25    
     Method.invoke(Object, Object...) line: 597    
     PerJoinpointAdvice.invoke(Invocation) line: 174    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     InvocationContextInterceptor.fillMethod(Invocation) line: 72    
     InvocationContextInterceptor_z_fillMethod_1407413958.invoke(Invocation) line: not available    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     InvocationContextInterceptor.setup(Invocation) line: 88    
     InvocationContextInterceptor_z_setup_1407413958.invoke(Invocation) line: not available    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     CachedConnectionInterceptor.invoke(Invocation) line: 62    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     TransactionScopedEntityManagerInterceptor.invoke(Invocation) line: 56    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     AllowedOperationsInterceptor.invoke(Invocation) line: 47    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     NullInterceptor.invoke(Invocation) line: 42    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     Ejb3TxPolicy(TxPolicy).invokeInOurTx(Invocation, TransactionManager) line: 79    
     TxInterceptor$Required.invoke(Invocation) line: 190    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     TxPropagationInterceptor.invoke(Invocation) line: 76    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     NullInterceptor.invoke(Invocation) line: 42    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     Ejb3AuthenticationInterceptorv2.invoke(Invocation) line: 186    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     ENCPropagationInterceptor.invoke(Invocation) line: 41    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     BlockContainerShutdownInterceptor.invoke(Invocation) line: 67    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     CurrentInvocationInterceptor.invoke(Invocation) line: 67    
     StatefulContainerInvocation(MethodInvocation).invokeNext() line: 102    
     ServiceContainer.localInvoke(Method, Object[]) line: 451    
     ServiceContainer.invoke(Object, SerializableMethod, Object[]) line: 608    
     SessionLocalProxyInvocationHandler(SessionProxyInvocationHandlerBase).invoke(Object, SerializableMethod, Object[]) line: 207    
     SessionLocalProxyInvocationHandler(SessionProxyInvocationHandlerBase).invoke(Object, Method, Object[]) line: 164    
     $Proxy379.initializing(ServerServiceLocator) line: not available    
     ServerServiceLocator.initializeHooks() line: 227    
     ServerServiceLocator.initialize() line: 245    
     ServerServiceLocator.start() line: 830    
     NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]    
     NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39    
     DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25    
     Method.invoke(Object, Object...) line: 597    
     ServiceContainer.invokeOptionalMethod(String) line: 369    
     ServiceContainer.lockedStart() line: 264    
     ServiceContainer(EJBContainer).start() line: 884    
     GeneratedMethodAccessor274.invoke(Object, Object[]) line: not available    
     DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25    
     Method.invoke(Object, Object...) line: 597    
     ReflectionUtils.invoke(Method, Object, Object[]) line: 59    
     ReflectMethodInfoImpl.invoke(Object, Object[]) line: 150    
     BasicMethodJoinPoint.dispatch() line: 66    
     KernelControllerContextAction$JoinpointDispatchWrapper.execute() line: 241    
     KernelControllerContextAction$JoinpointDispatchWrapper(ExecutionWrapper).execute(AccessControlContext) line: 47    
     KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContext, ExecutionWrapper) line: 109    
     KernelControllerContextAction.dispatchJoinPoint(KernelControllerContext, Joinpoint) line: 70    
     StartStopLifecycleAction(LifecycleAction).installActionInternal(KernelControllerContext) line: 221    
     StartStopLifecycleAction(InstallsAwareAction).installAction(KernelControllerContext) line: 54    
     StartStopLifecycleAction(InstallsAwareAction).installAction(ControllerContext) line: 42    
     StartStopLifecycleAction(SimpleControllerContextAction<T>).simpleInstallAction(T) line: 62    
     StartStopLifecycleAction(AccessControllerContextAction<S,T>).install(ControllerContext) line: 71    
     KernelControllerContextActions(AbstractControllerContextActions).install(ControllerContext, ControllerState, ControllerState) line: 51    
     AbstractKernelControllerContext(AbstractControllerContext).install(ControllerState, ControllerState) line: 348    
     AbstractKernelController(AbstractController).install(ControllerContext, ControllerState, ControllerState) line: 1631    
     AbstractKernelController(AbstractController).incrementState(ControllerContext, boolean) line: 934    
     AbstractKernelController(AbstractController).resolveContexts(ControllerState, ControllerState, boolean) line: 1082    
     AbstractKernelController(AbstractController).resolveContexts(boolean) line: 984    
     AbstractKernelController(AbstractController).change(ControllerContext, ControllerState, boolean) line: 822    
     AbstractKernelController(AbstractController).change(ControllerContext, ControllerState) line: 553    
     ServiceController.doChange(KernelController, ServiceControllerContext, ControllerState, String) line: 688    
     ServiceController.start(ObjectName) line: 460    
     ServiceDeployer.start(ServiceContext) line: 163    
     ServiceDeployer.deploy(DeploymentUnit, ServiceMetaData) line: 99    
     ServiceDeployer.deploy(DeploymentUnit, Object) line: 46    
     ServiceDeployer(AbstractSimpleRealDeployer<T>).internalDeploy(DeploymentUnit) line: 62    
     ServiceDeployer(AbstractRealDeployer).deploy(DeploymentUnit) line: 50    
     DeployerWrapper.deploy(DeploymentUnit) line: 171    
     DeployersImpl.doDeploy(Deployer, DeploymentUnit) line: 1439    
     DeployersImpl.doInstallParentFirst(Deployer, DeploymentContext) line: 1157    
     DeployersImpl.doInstallParentFirst(Deployer, DeploymentContext) line: 1178    
     DeployersImpl.install(ControllerContext, ControllerState, ControllerState) line: 1098    
     DeploymentControllerContext(AbstractControllerContext).install(ControllerState, ControllerState) line: 348    
     AbstractKernelController(AbstractController).install(ControllerContext, ControllerState, ControllerState) line: 1631    
     AbstractKernelController(AbstractController).incrementState(ControllerContext, boolean) line: 934    
     AbstractKernelController(AbstractController).resolveContexts(ControllerState, ControllerState, boolean) line: 1082    
     AbstractKernelController(AbstractController).resolveContexts(boolean) line: 984    
     AbstractKernelController(AbstractController).change(ControllerContext, ControllerState, boolean) line: 822    
     AbstractKernelController(AbstractController).change(ControllerContext, ControllerState) line: 553    
     DeployersImpl.process(List<DeploymentContext>, List<DeploymentContext>) line: 781    
     MainDeployerImpl.process() line: 702    
     MainDeployerAdapter.process() line: 117    
     ProfileDeployAction.install(Profile) line: 70    
     ProfileDeployAction(AbstractProfileAction).install(ProfileContext) line: 53    
     AbstractProfileService.install(ControllerContext, ControllerState, ControllerState) line: 361    
     ProfileContext(AbstractControllerContext).install(ControllerState, ControllerState) line: 348    
     ScopedProfileServiceController(AbstractController).install(ControllerContext, ControllerState, ControllerState) line: 1631    
     ScopedProfileServiceController(AbstractController).incrementState(ControllerContext, boolean) line: 934    
     ScopedProfileServiceController(AbstractController).resolveContexts(ControllerState, ControllerState, boolean) line: 1082    
     ScopedProfileServiceController(AbstractController).resolveContexts(boolean) line: 984    
     ScopedProfileServiceController(AbstractController).change(ControllerContext, ControllerState, boolean) line: 822    
     ScopedProfileServiceController(AbstractController).change(ControllerContext, ControllerState) line: 553    
     AbstractProfileService.activateProfile(ProfileKey) line: 306    
     ProfileServiceBootstrap.start(Server) line: 271    
     ServerImpl(AbstractServerImpl).start() line: 461    
     Main.boot(String[]) line: 221    
     Main$1.run() line: 556    
     Thread.run() line: 619    
 
 <?xml version="1.0" encoding="UTF-8"?>
 <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
              version="1.0">
     <persistence-unit name="hibersyncDataSource" transaction-type="JTA">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
         <jta-data-source>java:/jdbc/PostgresDS</jta-data-source>
         <properties>
             <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
             <property name="hibernate.connection.release_mode" value="auto" />
             <property name="hibernate.max_fetch_depth" value="0" />
             <property name="hibernate.hbm2ddl.auto" value="update" />
             <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
             <property name="org.hibernate.dialect.PostgreSQLDialect" value="update"/>
             <property name="hibernate.transaction.manager_lookup_class" value ="org.hibernate.transaction.JBossTransactionManagerLookup" />
             <!--property name="jta.UserTransaction" value="java:comp/UserTransaction"/-->                          
             <property name="hibernate.show_sql" value="false" />
             <property name="hibernate.c3p0.minPoolSize" value="1" />
             <property name="hibernate.c3p0.maxPoolSize" value="5" />
             <property name="hibernate.c3p0.timeout" value="600" />
             <property name="hibernate.c3p0.max_statement" value    ="50" />
             <property name="hibernate.c3p0.testConnectionOnCheckout" value="false" />
         </properties>
     </persistence-unit>
 </persistence>

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/531925#531925




More information about the jboss-user mailing list