• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Devaka Cooray
Marshal
Pie
Posts: 4880
402
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
com.emthuware.ets.scbcd.v5.2.292
 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Cuetu Mayu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic