Question

Project comprise of EJB 2.0 and EJB 3.0 Beans. I converted a session bean from EJB 2.0 to EJB 3.0 and as I start the project, it initialize the session bean multiple times. The session bean call other session beans which in turn calls different methods of this session bean. As long as it was EJB 2.0 session bean, only one instance was initialized but now multiple instances are initialized.

UtilitiesController Session Bean initiates a thread which calls Miscellaneous Class (Helper Class POJO) which in return calls ProductScheme Session Bean which calls ServerGlobalValues (Helper Class POJO) and it calls UtilitiesController Session Bean

Following are the logs:

setSessionContext Called!
setSessionContext Called!
@PostConstruct method Called!
Starting Initialization
<2013-06-07 15:03:53.535--ServerSession(316201757)--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073>
<2013-06-07 15:03:53.535--ServerSession(316201757)--Server: 10.3.5.0>
setSessionContext Called!
setSessionContext Called!
@PostConstruct method Called!
Starting Initialization
<2013-06-07 15:03:53.691--ServerSession(316201757)--The DatabaseSession has an external transaction controller defined by something other than the ServerPlatform. EclipseLink will permit the override of the external transaction controller, but we recommend you consider the alternative of subclassing org.eclipse.persistence.platform.server.ServerPlatformBase and override getExternalTransactionControllerClass().>
<2013-06-07 15:03:53.691--ServerSession(316201757)--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073>
<2013-06-07 15:03:53.691--ServerSession(316201757)--Server: 10.3.5.0>
setSessionContext Called!
setSessionContext Called!
@PostConstruct method Called!
Starting Initialization
<2013-06-07 15:03:53.722--ServerSession(316201757)--The DatabaseSession has an external transaction controller defined by something other than the ServerPlatform. EclipseLink will permit the override of the external transaction controller, but we recommend you consider the alternative of subclassing org.eclipse.persistence.platform.server.ServerPlatformBase and override getExternalTransactionControllerClass().>
<2013-06-07 15:03:53.722--ServerSession(316201757)--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073>
<2013-06-07 15:03:53.722--ServerSession(316201757)--Server: 10.3.5.0>
setSessionContext Called!
setSessionContext Called!
@PostConstruct method Called!
Starting Initialization
<2013-06-07 15:03:53.847--ServerSession(316201757)--The DatabaseSession has an external transaction controller defined by something other than the ServerPlatform. EclipseLink will permit the override of the external transaction controller, but we recommend you consider the alternative of subclassing org.eclipse.persistence.platform.server.ServerPlatformBase and override getExternalTransactionControllerClass().>
<2013-06-07 15:03:53.847--ServerSession(316201757)--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073>
<2013-06-07 15:03:53.847--ServerSession(316201757)--Server: 10.3.5.0>
setSessionContext Called!
setSessionContext Called!
@PostConstruct method Called!
Starting Initialization
<2013-06-07 15:03:53.879--ServerSession(316201757)--The DatabaseSession has an external transaction controller defined by something other than the ServerPlatform. EclipseLink will permit the override of the external transaction controller, but we recommend you consider the alternative of subclassing org.eclipse.persistence.platform.server.ServerPlatformBase and override getExternalTransactionControllerClass().>
<2013-06-07 15:03:53.879--ServerSession(316201757)--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073>
<2013-06-07 15:03:53.879--ServerSession(316201757)--Server: 10.3.5.0>
javax.ejb.EJBTransactionRolledbackException: EJB Exception: ; nested exception is: Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.JPQLException

As it can be seen from logs that setSessionContext is called twice for each instance creation and @PostConstruct method is also called before initialization.

Can anyone please point out what can be the reason behind such behaviour. Is there any configuration missing?

Was it helpful?

Solution

I forgot to mention that the helper classes (i.e Miscellaneous Class & ServerGlobalValues) are singleton and the behaviour of singleton class is unexpected. I found that the reason for multiple instances has relation with calling getInstance() of helper classes. If I call getInstance() inside PostConstruct, I see multiple instances of both helper classes and controller but moving it to class level resolves multiple instance issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top