aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes A stateless session bean cannot access resource managers in a @PostConstruct method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "A stateless session bean cannot access resource managers in a @PostConstruct method." Watch "A stateless session bean cannot access resource managers in a @PostConstruct method." New topic
Author

A stateless session bean cannot access resource managers in a @PostConstruct method.

Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

This statement is quoted from the explanation of a mock exam. I failed to understand this. Why?

Consider the following code example from EJB in action:

Now, is javax.sql.DataSource and javax.sql.Connection not resource managers?

Thanks.


SCJP, SCJD, SCWCD, SCBCD, SCEA
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Jiafan Zhou wrote:This statement is quoted from the explanation of a mock exam.


When you are quoting contents from mock exams, please let us know the source that where you got it from. So that we can continue the discussion.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

com.emthuware.ets.scbcd.v5.2.292
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hi,

i think that javax.sql.DataSource is a Resoure Manager Factory and javax.sql.Connection is a Resource Manager. An example of the use is shown in the MZ guide:



SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

So the statement in the title is wrong, isn't it?

That is:

A stateless session bean cannot access resource managers in a @PostConstruct method.

It will be a huge limitation if it is true. I don't see a reason why it cannot.

I will find the original question and post it here soon.

Thanks
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9619
    
    2

I do not see any reason as to why we could not access any resource managers in the PostConstruct. Afterall it is meant for that puupose. The only place where you cannot do this is in the constructor.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Cuetu Mayu
Greenhorn

Joined: Jul 08, 2013
Posts: 2
According to the Enthuware's forum, this is why:

"They can access from SFSB but not SLSB. There must be a valid transaction context."

Here you are the source where I got it from.

Jarek Wa
Greenhorn

Joined: Jan 12, 2012
Posts: 6
Hi,

Only Singleton Bean can access resource managers in PostConstruct and PreDestroy (because it is the only one for which these two methos can be associated with transaction context).

Specification, 4.8.6 , table 3:

SessionContext methods: getBusinessObject, getRollbackOnly, setRollbackOnly, getTimerService, lookup, getContextData
JNDI access to java:comp/env
Resource manager access
Enterprise bean access
EntityManagerFactory access
EntityManager access
TimerService and Timer methods


And here are the operations you can access from PostConstruct, PreDestroy lifecycle callback interceptor methods of Stateless Session Bean:

Specification, 4.7.2, table 2:

SessionContext methods: getBusinessObject, getEJBHome, getEJBLocalHome, getEJBObject, getEJBLocalObject, getTimerService, lookup, getContextData
JNDI access to java:comp/env
EntityManagerFactory access


Generally you cannot use resource managers as SFSB and SLSB PostConstruct and PreDestroy methods, because they run in unspecified transaction context.

HTH,
J
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A stateless session bean cannot access resource managers in a @PostConstruct method.