Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enthuware mock exam question 11 from Test 1

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the statements are true regarding the following enterprise bean code snippet appearing in a business method?


Code

...
Context initContext = new InitialContext();

DataSource ds1 = (DataSource)initContext.lookup("java:comp/env/db1");
Connection con1 = ds1.getConnection();
DataSource ds2 = (DataSource)initContext.lookup("java:comp/env/db2");
Connection con2 = ds2.getConnection();

UserTransaction tx = ejbContext.getUserTransaction();
tx.begin();
//use the connection to update database 1.
//use the connection to update database 2.
tx.commit();
con1.close();
con2.close();
...


Select 1 correct option.

This code is invalid in all kinds of EJBs.

This code is invalid in Session beans.

This code is invalid in Entity beans.

This code is invalid in Message driven beans.

This code is invalid in Stateful Session beans.

The correct answer is : This code is invalid in Entity beans.

Can someone please explain why is it so?? they have not provided the explanation.

thanks,
trupti
 
Yi Fang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Entity Bean can only use Container Managed Transaction. The code clearly try to use BMT.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition. for EJB 1.x, EntityBean can use BMT, however, for EJB 2.0, BMT is prohibit for EntityBean.

Nick
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yi Fang:
An Entity Bean can only use Container Managed Transaction. The code clearly try to use BMT.


Welcome to the Ranch, Yi Fang!!!

You did a nice explanation to nigam as well....
 
Girija Siva
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get confused between CMP and CMT Entity beans are always CMT whether they are BMP or CMP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic