• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 6884
1312
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
com.emthuware.ets.scbcd.v5.2.292
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic