• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Answers of Sun's Free Proficiency Assessment

 
Ranch Hand
Posts: 102
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Note:- answers in Bold Text

1. Which statement correctly identifies the architectural goals of the designers of the EJB architecture?
The EJB architecture supports the development, deployment, and use of web services.
The EJB architecture only supports interoperability with programs written in the Java language.
The EJB architecture addresses the development and deployment of EJB components, but the runtime aspect is left completely to the discretion of the container providers.
The EJB architecture requires that users be aware of the low-level connection pooling aspects and multi-threading characteristics of the Java EE platform.

2. What programming restrictions are defined in the EJB specifications?
An enterprise bean must NOT attempt to listen on a socket.
A session bean class must NOT have any superclasses and/or superinterfaces.
An enterprise bean can directly read a file descriptor.
An entity bean class need NOT implement a public zero-argument constructor.

3. An enterprise bean packaged in an ejb-jar returns instances of a Television class as a result for one of its business methods. The developer has been asked to create an associated ejb-client JAR file. What files must be placed in this ejb-client JAR for it to be valid?
The ejb-jar file (by inclusion or by reference)
The Television class (by inclusion or by reference)
Stubs of all enterprise classes referenced by the ejb-client
The DTDs and schemas of all XML messages used by the client

4. A non-transient String field in an interceptor associated with a stateful session bean is set to "Hello" when the stateful session bean is passivated.

What will the state of the field be after the bean is again activated?
The specification states that the value will be undefined.
It will be set to null.
It is set to "Hello".
The bean will be associated with an arbitrary interceptor instance after activation, and so can have whatever value the field is set to in that interceptor instance.

5. The EJB Timer service can be used to ensure that the EJB container invokes a timeout method on a bean at a specified time or after a specified period. Which two types of beans support this Timer service? (Choose two.)
Stateless session beans
Stateful session beans
EJB 2.1 entity beans
EJB 3.0 entities

6. Which statement about EJB 2.x and EJB 3.0 API interoperability is correct?
A stateless session bean written to the EJB 3.0 API can be adapted to an EJB 2.1 client interface.
The developer cannot mix APIs. For example, the developer cannot write an EJB 3.0 session bean while also implementing an EJB 2.1 EJBHome interface.
The EJB 2.1 API requires the use of a stateful session bean's home interface to obtain a reference to the bean's component interface. The developer cannot use dependency injection to obtain a reference to such a home interface in an EJB 3.0 client of such a bean.
An adapter class has to be used when accessing EJB 2.0 environment variables of a stateless session bean, when such a bean is deployed in an EJB 3.0 container.

7. Which statement characterizes stateful session beans?
They allow the PostConstruct, PreDestroy, and PrePassivate life-cycle callbacks.
They require home interfaces.
When a client looks up a stateful session bean in the JNDI, the same bean is returned every time.
They are asynchronous message consumers.

8. Given an interface:

5. public interface ValueInt {
6. public int getVal();
7. int getBarPackage();
8. }
Here is an excerpt from a stateless session bean that implements this interface:

10. @Stateless
11. public class FloatBean implements ValueInt {
12. public int getVal() { return 4; }
13. public int getBarPackage() { return 2; }
50. }
What methods are exposed to local clients of this stateless session bean?
no methods are exposed
getVal
getBar
getVal and getBarPackage

9. The deployment descriptor for the Foo session bean looks similar to this:

10. <enterprise-beans>
11. <session>
12. ...
13. <ejb-name>Foo</ejb-name>
14. <ejb-class>ms.FooBean</ejb-class>
15. ...
16. <resource-ref>
17. <res-ref-name>jdbc/BarDB</res-ref-name>
18. <res-type>javax.sql.DataSource</res-type>
19. <res-auth>Container</res-auth>
20. <res-sharing-scope>Shareable</res-sharing-scope>
21. </resource-ref>
22. ...
23. </session>
24.</enterprise-beans>
Assume that a deployer binds this to an actual resource. The implementation of Foo contains a reference to a Context object bound to the variable initCtx and a reference to a SessionContext object bound to the variable ctx. Which statement successfully retrieves the datasource?
@Resource DataSource ds;
(DataSource) ctx.lookup("java:comp:env/jdbc/BarDB");
initCtx.lookup("java:comp/env/jdbc/BarDB");
@Resource(name=?jdbc/BarDB?, type=javax.sql.DataSource)

10. Which statement is true about message-driven beans?
A message-driven bean can register with the EJB Timer Service for timeout callback notifications.
A message-driven bean must implement the javax.ejb.MessageDrivenBean interface.
Message-driven beans only support the PostConstruct life-cycle callback interceptor.
Message-driven beans do NOT support the AroundInvoke business method interceptors.

11. A developer is given a JMS message-driven bean, which has no descriptors or metadata that describe acknowledge modes or subscription durability. In addition, the message-driven bean uses bean-managed transactions and is subscribed to a topic. What two message-driven bean behaviors can the developer expect to see? (Choose two.)
If a message is received, the container automatically acknowledges it.
If a message is received, the container does NOT automatically acknowledge it.
Messages will NOT be missed, even if the EJB server is NOT running.
Messages can be missed if the EJB server is NOT running.
Specifying subscription durability for a topic has no effect.

12. Given a snippet of a JMS message-driven bean, configured to listen on a queue.

@MessageDriven
public class LetterBean implements MessageListener {
@Resource MessageDrivenContext ctx;
public void onMessage(Message msg) {
ctx.setRollbackOnly();
}
}
A JMS server receives a message and delivers it to this queue. After executing the onMessage method, no exceptions are thrown.

Which statement is correct about this message-driven bean?
The message-bean is using bean-managed transactions.
The server receives an acknowledgment sent by the LetterBean instance.
The JMS server sends the same message more than once.
The LetterBean instance that receives the message immediately moves into the "does NOT exist" state.

13. Given an excerpt of a Book entity (it is just missing the import statements):

10. @Entity
11. public class Book implements Serializable {
12. @Id
13. @GeneratedValue(strategy = GenerationType.AUTO)
14. private Integer id;
15. String bookName;
16. protected int price;
17. enum Status {IN, OUT};
18. @Enumerated( EnumType.ORDINAL )
19. Status status;
20. transient int bar;
21. java.util.Map<Integer, String> comments;
22. protected Book() {};
23. }
No descriptors are used.

Which statement is correct about this entity?
There is an error on line 11. It must NOT implement Serializable.
Adding a single @Transient annotation makes this entity valid.
The visibility declarations on some of the variables causes an exception.
The enumeration or its field definition on lines 17, 18, or 19 is NOT valid.
There is an error in the identity definition on lines 12, 13, or 14.

14. All of the entities in a persistence unit have the following two lines defining their primary keys:

10. @GeneratedValue(generator="MyGenerator", strategy = GenerationType.TABLE)
11. private int id;
The deployment descriptor has only the following few lines pertaining to primary keys:

20. <table-generator>
21. <name>MyGenerator</name>
22. <table>MyTable</table>
23. <pk-column-name>NAME</pk-column-name>
24. </table-generator>
Which statement is correct?
Only AUTO, TABLE, and IDENTITY generation types are made available by a persistence provider.
The different entities within the persistence unit can share the same generator.
The provider must generate a suite of tables when it processes the table-generator tag.
The MyTable table is accessed each time a new entity is persisted to the database to ensure that a unique identifier is assigned for the entity.

15. There are two tables in a database, Celery and Carrot. Celery contains a foreign key to Carrot. Each table has a primary key, and there are no other constraints on the tables. No descriptors are used, and in the following options each scenario depicts all the mapping information pertaining to the relationship. Which entities accurately model this database scenario?
@Entity Celery {
/* ... */
}
@Entity Carrot {
@ManyToOne
Celery celery;
/* ... */
}

@Entity Celery {
@ManyToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}


@Entity Celery {
@OneToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}

@Entity Celery {
/* ... */
}
@Entity Carrot {
@OneToOne
Carrot carrot;
/* ... */
}


16. A domain model comprises two entities: Dog and Flea. The developer is required to construct these entities so that the Dog and Flea entities are in a unidirectional one-to-many relationship.

Which statement about implementing this model is NOT correct?
The @OneToMany annotation must be placed in the Dog entity.
The @ManyToOne annotation must NOT be used on the Flea entity.
A join table can be used to implement this relationship.
The Flea entity will be the owning side of the relationship.

17. Given the definition for an entity, Book:

10. @Entity
11. public class Book {
12. @Id Integer id;
13. @Column(name="NAMEBOOK")
14. String bookName;
15. public java.util.Date loanDate;
16. }
The associated descriptor file has the following snippet pertaining to this entity:

20. <entity class="Book" metadata-complete="true">
21. <table name="BOOKTB"/>
22. <attributes>
23. <basic name="bookName">
24. <column name="TOMENAME"/>
25. </basic>
26. <basic name="loanDate">
27. <temporal>DATE</temporal>
28. </basic>
29. </attributes>
30. </entity>
No other parts of the deployment descriptor affect this configuration. Which statement about the persistent unit and descriptor is correct?
The descriptor will ensure that the table BOOKTB is used to map the entity Book, and that bookName is mapped to column NAMEBOOK within this table.
The descriptor ensures that the table BOOKTB is used to map the entity Book, and that bookName is mapped to column TOMENAME within this table.
This persistent unit does NOT deploy because an annotation is missing on the Book entity class.
This persistent unit does NOT deploy because the descriptor information is NOT complete.

18. Entities can be in a new, managed, detached, or removed state. Which statement is correct about these states?
Removing an entity in the removed state, causes an IllegalArgumentException to be thrown.
Detached entities are associated with a persistence context, but no longer have a persistent identity.
If an entity in the new state is removed, any cascaded removes to referenced objects from this new entity, are still carried out.
Immediately removing an entity after creating and persisting it, within the same transaction, causes an IllegalArgumentException to be thrown.

19. Given:

10. import javax.persistence.*;
11. public class BookViews {
12. public static void main (String[] args) {
13. EntityManagerFactory emf = Persistence.createEntityManagerFactory("Book");
14. EntityManager em = emf.createEntityManager();
15. em.getTransaction().begin();
16. Book b = (Book) em.createQuery("SELECT b FROM Book b").getSingleResult();
17. b.setAccessed(b.getAccessed() + 1);
18. em.getTransaction().commit();
19. em.close();
20. emf.close();
21. }
22. }
Assume that the Book entity exists, that the appropriate configuration files are in place, and that there is a Book entity in the persistent store.

Which statement about this code, and about resource-local/JTA entity managers in general, is correct?
This code compiles and executes fine in a Java SE environment.
The calls on line 15 and 18 are illegal.
It is illegal to write this sort of resource-local entity manager code in a Java EE environment.
The default entity-manager transaction type should have been set on line 13.

20. Which method of the EntityManager API is used to control the life-cycle of an application-managed persistence context?
EntityManager.remove
EntityManager.refresh
EntityManager.joinTransaction
EntityManager.getReference

21. Which statement about persistence units and packaging is correct?
Every persistence unit must always have the persistence.xml and orm.xml configuration files.
The persistence.xml file can be used to define more than one persistence unit.
Mapping metadata for a class can be specified using annotations, or in the XML configuration files, but NOT in both.
When a persistence unit is packaged in a WAR, the persistence.xml file must be located in the /META-INF directory off the root of the WAR package.

22. Given an excerpt from an entity:

10. @Entity
11. public class Koala {
12. int children;
13. @Id
14. private Integer id;
15. /* ... */
16. }
The following code was written to find the sum and average number of children across all Koala entities (assume the variable em is bound to a valid EntityManager instance):

20. String query = "SELECT SUM(k.children), AVG(k.children) from Koala k";
21. Query q = em.createQuery(query);
22. Object[] res = (Object []) q.getSingleResult();
Which two statements are correct? (Choose two.)
If there are no Koala entities in the database, the variable res is set to null after the code exits on line 22.
If there are no Koala entities in the database, the variable res contains an array of two null values.
If there are no Koala entities in the database, the variable res contains an array holding the values null and 0 respectively.
If there are Koala entities, the variable res contains an array with values of type Long and Double, respectively.
This code throws a runtime exception.

23. A domain model for a corporation includes a User entity that is in a one-to-many relationship with a Pen entity. A developer wants to select all User entities that have a single Pen. Which two queries will do this? (Choose two.)
SELECT us from User us WHERE 1 = ANY(SELECT COUNT(p) from us.pens p)
SELECT us from User us WHERE ANY(1 = SELECT COUNT(p) from us.pens p)
SELECT us from User us WHERE 1 = ALL(SELECT COUNT(p) from us.pens p)
SELECT us from User us WHERE SOME(1 = SELECT COUNT(p) from us.pens p)
SELECT us from User us WHERE 1 = ANY(SELECT COUNT(us.pens))

24. Given the following entity bean:

10. @Entity
11. @NamedQuery(name="myname", query="select c from Crumble c where c.id=:val")
12. public class Crumble {
13. @Id private Integer id;
14. }
Each of the following Java technology statements create Query objects, where em refers to an entity manager. Which statement returns a Crumble instance with a primary key of 20?
em.createNativeQuery("myname").setParameter(1, "val=20")
em.createNamedQuery("myname").setParameter("val", 20)
em.createNamedQuery("myname").setParameter(20, 1)
em.createNamedQuery("myname").setParameter(1, 20)

25. Which statements about transaction attributes and propagation is correct?
A message-driven bean's listener methods can only have a REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute.
An enterprise bean's timeout callback method can only have a REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute.
An enterprise bean implementing the javax.ejb.SessionSynchronization interface can only have a REQUIRES or REQUIRES_NEW transaction attribute.
A session bean's business method cannot have a MANDATORY transaction attribute.

26. Given an excerpt from a stateful session bean:

10. @Stateful
11. public class MyStatefulBean implements MyStateful, SessionSynchronization {
12. @Resource SessionContext ctx;
13. public void afterCompletion(boolean f) {}
14. public void beforeCompletion() { ctx.setRollbackOnly(); }
15. public void afterBegin() {}
16. @Remove
17. public void inc() {}
18. }
The MyStateful interface is a local business interface that declares inc to be a business method. No deployment descriptor is used. A stateless session bean using container-managed transactions has a business method that acts as a client:

20. @TransactionAttribute(TransactionAttributeType.REQUIRED)
21. public String doIt() {
22. ms.inc();
23. }
The method doIt is called without a transactional context. Which order properly reflects the order of method invocation?
doIt, afterBegin, inc
doIt, inc, afterBegin, beforeCompletion
doIt, inc, beforeCompletion, afterBegin, afterCompletion
doIt, inc, afterBegin, beforeCompletion, afterCompletion
doIt, afterBegin, inc, beforeCompletion, afterCompletion

27. Given some code from a stateful session bean:

10. @Stateful
11. @TransactionAttribute(TransactionAttributeType.REQUIRED)
12. public class USBean implements US {
13. @PreDestroy
14. public void slashstar() {}
15. public void oops() {
16. throw new javax.persistence.PersistenceException();
17. }
18. }
It has no descriptor. A client makes a call to oops, which runs in the context of the client's transaction. What action would you expect the container to perform, if any, after this transaction is thrown?
The exception is rethrown.
An EJBException is thrown by the container to the client.
It discards the instance of the session bean.
It performs some actions and eventually executes the slashstar method.
It is the responsibility of the bean provider to properly catch and handle such exceptions.

28. Given an interface:

4. @Local
5. public interface MyI {
6. public Set go(Set s);
7. }
Given an excerpt from a stateful session bean that implements this business interface:

9. @Stateful
10. @TransactionAttribute(TransactionAttributeType.REQUIRED)
11. public class MyStatefulBean implements MyI {
12. @Resource SessionContext ctx;
13. public Set go(Set s) {
14. ctx.getRollbackOnly();
15. ctx.getEJBOjbect();
16. ctx.getEJBHome();
17. throw new Exception("Will I, won't I?");
18. }
50. }
No deployment descriptor is used. Which statement is correct?
An exception is thrown on line 14.
An exception is thrown on line 15.
An exception is thrown on line 16.
An exception is thrown on line 17.

29. Which two roles are responsible for creating or modifying security roles in a bean's annotations or deployment descriptor? (Choose two.)
Bean Provider
Application Assembler

Deployer
EJB Server Provider
EJB Container Provider
System Administrator

30. Given an excerpt from a descriptor for a stateless session bean:

10. <session>
11. <ejb-name>EN</ejb-name>
12. <ejb-class>com.sun.ejb.EClassBean</ejb-class>
13. <security-role-ref>
14. <role-name>AGENTN</role-name>
15. <role-link>AGENTL</role-link>
16. </security-role-ref>
17. </session>
If ctx is an injected SessionContext, which of the following calls would you expect to see in the bean implementation given this descriptor?
ctx.getCallerPrincipal()=="AGENTL"
ctx.getCallerPrincipal()=="AGENTN"
ctx.isCallerInRole("AGENTN")
ctx.isCallerInRole("AGENTL")
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Alim . The Answers were in great demand . By the way , did you do it yourself ?
 
Alim Atar
Ranch Hand
Posts: 102
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
With the help of specifications i solved,few were wrong which are again solved correctly.
Now these all are correct answers.

Regards,
Alim

Originally posted by bernard savary:
Thanks a lot Alim . The Answers were in great demand . By the way , did you do it yourself ?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good work
My score in test is very low it is 50 % it is very disappointing to me as i am planning to go to exam by the end of month.
Any suggestion to improve it !
My study kit include
1. Enterprise JavaBean 3.0 O'Reilly
2. SCBCD 5.0 Study Gide by Mikalai Zaikin
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alim,

Great work... Much appreciated..
 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q17. Given the definition for an entity, Book:

Why isn't the descriptor not complete. Isn't the class missing @GeneratedValue annotation

Q19) Isn't it illegal to write Resource_Local code on EE. I had read that

Q26) WHY IS BEFORECompletion & afterCompletion not being called? Should the answer be the last options

Q27). PersistenceException is an run time exception. In this case, it would throw EJBException & discard the instance.

This assesment test is preety tough. I got just 67%
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got most of answers except 26. Why is aftercompletion & before completion methods not called in this case?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q26:

doIt(): transaction is started.

from spec p347:
The container invokes the afterBegin method on an instance before it invokes the first business method in a transaction.

inc() is called. It is marked with @Remove, so the bean is destroyed.
If there were any @PreDestroy, it would be called, but there is none.

doIt() completes and the transaction commits. afterBegin() and afterCompletion() are never called, because the bean no longer exists.

from spec (p. 76):
If the Remove method completes successfully
or if the Remove methods throws an application exception for which retainIfException is not true
or if a system exception is thrown,
SessionSynchronization methods are not called on the bean instance.
[ July 09, 2008: Message edited by: E Lievaart ]
 
E Lievaart
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q17:
metadata-complete="true" is set so all annotations on the class are ignored anyway.
The DD doesn't have an <id> element and it MUST be specified for an Entity.

By the way, @GeneratedValue (or <generated-value> ) is optional.
You can choose to have the application provide pk's.

Q19:
JPA spec (p.118):
Both JTA entity managers and resource-local entity managers are required to be supported in Java EE
web containers and EJB containers.Within an EJB environment, a JTA entity manager is typically used.
In general, in Java SE environments only resource-local entity managers are supported.

Q27:
It is indeed a RuntimeException, so the bean is discarded.
The only reason I can think of that throwing an EJBException is not the correct answer,
is because in some cases a RemoteException is thrown.
[ July 09, 2008: Message edited by: E Lievaart ]
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alim, hi to all ranchers,

I know this thread is quite old but I still need the helpful help of ranchers

I passed this assessment with 63% and I go to the exam at the end of the month. I still have a few question about this assessment

Q9) Just to be sure : answer b) and d) are a correct way to retrieve the datasource, but there is a small syntax error (":" instead of "/" for example), which makes answer b) and d) incorrect, am I right?

Q12) Why the JMS server would sends the same message more than once? I thought that when a message was delivers to a queue, only one MDB consumes it, so there is no need for the JSM to redeliver it.

Q14) answer d) seems also correct to me, since the table_generator is used for the id, the MyTable is accessed each time a new entity is persisted into the database. Why is statement d) wrong?

Q15) Celery contains a foreign key to Carrot, this means that option b) and d) are correct. Why is d) incorrect, according to Alim?


Thanks to all,

David.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q9)
Option:
(DataSource) ctx.lookup("java:comp:env/jdbc/BarDB");
is incorrect for 2 reasons:
i) SessionContext lookup always takes name relative to java:comp/env
ii) there is a typo -> "java:comp:env" should be "java:comp/env"

Option:
@Resource(name=?jdbc/BarDB?, type=javax.sql.DataSource)
is incorrect, it won't compile. Question marks should be double quotes.

Q12)
Message acknowledge by container is part of committing container managed transaction. In this case the bean marks transaction for rollback, so transaction is not committed, so message is not acknowledged, so JMS server will resend the message.

Q14)
Option d is wrong, because table generator has attribute allocationSize with default value od 50, so approximately, the table will be accessed every fifty created entities.

Q15)
In option D the Carot has reference to Carot, so the relationship would by one-to-one carrot with carrot, no celery.
 
david boureau
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tomaszz,

Thanks a lot, this helps a lot. For question 15) I didn't read the answer carefully enough, for others, I wouldn't have known.

Good night,

David.
 
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

# Which statements about transaction attributes and propagation is correct?
# A message-driven bean's listener methods can only have a REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute.
# An enterprise bean's timeout callback method can only have a REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute.
# An enterprise bean implementing the javax.ejb.SessionSynchronization interface can only have a REQUIRES or REQUIRES_NEW transaction attribute.
# A session bean's business method cannot have a MANDATORY transaction attribute.





Doubt in question 25

I understand that both MDB's and timout callback methods do not have client's and are invoked by the container.

In this case why is there a difference in the allowed transaction attributes for the two methods ?

i.e MDB REQUIRED, NOT_SUPPORTED transaction attribute.

and timeout call back

REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute.


Thanks
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

# 20. String query = "SELECT SUM(k.children), AVG(k.children) from Koala k";
# 21. Query q = em.createQuery(query);
# 22. Object[] res = (Object []) q.getSingleResult();
# Which two statements are correct? (Choose two.)
# If there are no Koala entities in the database, the variable res is set to null after the code exits on line 22.
# If there are no Koala entities in the database, the variable res contains an array of two null values.
# If there are no Koala entities in the database, the variable res contains an array holding the values null and 0 respectively.
# If there are Koala entities, the variable res contains an array with values of type Long and Double, respectively.
# This code throws a runtime exception.



Should not this give NoResultException ??
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I failed with 50%!
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone kindly explain me questions

12
13
15
16
17
20 - why does not it throw exception if there are not koalas in the database, as is the behavior of the getSingleResult() method?
26
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Concerning the Koala question: The getSingleResult() method doesn't throw an exception because the query returns a result even if there are no Koalas in the table. That's because aggregate functions have a special behavoir if there are no rows they can be applied to. See JPA spec 4.8.4:

If SUM, AVG, MAX, or MIN is used, and there are no values to which the aggregate
function can be applied, the result of the aggregate function is NULL.

If COUNT is used, and there are no values to which COUNT can be applied, the result
of the aggregate function is NULL.


 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, Can any one help me with the remaining queries..?
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone?
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Niranjan,
I got a 50% too and I am not a happy camper. Going to your questions, 12 has been anwered in the thread, so I am pasting it here. I will look into the other questions as I have more time.

Q12)
Message acknowledge by container is part of committing container managed transaction. In this case the bean marks transaction for rollback, so transaction is not committed, so message is not acknowledged, so JMS server will resend the message.



Let me know what is not clear in the above explanation and I can try to explain further?

I also tried this using jboss and the message was redelivered 6 times and there was a message on the jboss command window something to the extent of the message redelivered 6 times. My onMessage method looks like this. "In onmessage" was printed 6 times.



The struggle continues
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it Pramod! Thanks for the explanation!
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 26, I ran this in JBoss 4.2.2 and I am seeing beforeCompletion executed. Here is the output I am seeing
I have a sysout line in afterCompletion, "In afterCompletion" which is not displayed, but I see some warning message in the console as shown below in bold.

10:31:58,772 INFO [STDOUT] In doIt
10:32:16,880 INFO [STDOUT] In afterBegin
10:32:16,880 INFO [STDOUT] In inc
10:32:16,880 INFO [STDOUT] In beforeCompletion
10:32:16,880 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@bff4b8

When the container tries to commit the transaction in doIt method of the stateless bean, it throws a RollbackException because the transaction has been rolled back. The RollbackException is wrapped in a RuntimeException and the RuntimeException is then thrown to the client. Please note the method inc() here joins the transaction of method doIt().

I want to say the answer is e or is the container I am using non compliant with the spec. I would like to hear what others have to say.
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent work done in this post ....


At least one mock with simple language & correct answers.
Thanks.

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Very good set of questions.
I have some doubts regarding the question 4


4. A non-transient String field in an interceptor associated with a stateful session bean is set to "Hello" when the stateful session bean is passivated.

What will the state of the field be after the bean is again activated?
The specification states that the value will be undefined.
It will be set to null.
It is set to "Hello".
The bean will be associated with an arbitrary interceptor instance after activation, and so can have whatever value the field is set to in that interceptor instance.



I only want to be shore that I understand why the answer for this question is :


It is set to "Hello".



My explication is : the interceptors has the same lifecyle with the intercepted bean. That means our interceptor exist as long as the (intercepted) statefull bean exist, more a interceptor can carry state. So in this way if the string field goes "hallo" once and the interceptor leave as long as the bean the field will remain "hallo" also after the bean and the interceptor go active.

Am I right or do I miss something here.

Regards,
Mihai
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q8 - I think you have made a mistake : there is no annotation before interface (no @Remote, or @Local), so NO method will be available as EJB methods
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Promod is right about Q26:
"doIt, afterBegin, inc" can never be the right solution.

The method beforeCompletion must be entered to execute ctx.setRollbackOnly();
The method will return with no exception.

In my unterstanding of the API, the method afterCompletion(boolean f) will also be called.
From the method signature with the boolean parameter it is clear that it should also be called
in case of a rollback.

Trying this in JBoss 4.2.3.GA, I get the println of beforeCompletion(), and concerning afterCompletion() I get a
similar WARN from the arjLoggerI18N as Promod. This warning occurs also in case of a normal commit, so I think it's a JBoss problem.

Klaus
 
Klaus Schultz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q8 - I found in chapter 4.6.6 of the spec the following:
"If bean class implements a single interface, that interface is assumed to be the business
interface of the bean. This business interface will be a local interface unless the
interface is designated as a remote business interface...."

So both methods of the interface will be exposed (locally).
 
Klaus Schultz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q26 - to correct my last post.
I didn't read the post of E Lievaart from Jul 2008.
His quotation of the spec is right, JBoss is wrong.
So the solution should be "doIt, afterBegin, inc".
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely 13 is incorrect, I would have thought option E would be correct: "There is an error in the identity definition on lines 12, 13, or 14.". The reason being, this entity is using Field-based Access and the id field is marked as private. It's my understanding that when using field based access all fields have to be public or protected.

I tried to find a reference in the spec to back my self but will have to make do with Section 7.2.2 of EJB3 in Action:

If you want to use field-based access, you can declare all your POJO persisted data fields public or protected and ask the persistence provider to ignore getters/setters altogether.



Thoughts?

 
Klaus Schultz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ross Crockett wrote: using Field-based Access


The fields can be declared even private in case of Field-based Access.
 
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I've got some doubts regarding question #19. In the code snippet we've got:



We are not 100% sure that there is only one entry in the Book table (or table has at least one entry at all).
Therefore this query may throw NoResultException or NonUniqueResultException!

BTW. Any explanation regarding question #25?

Regards,
Krzysztof
 
Klaus Schultz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Krzysztof Koziol wrote:

I've got some doubts regarding question #19. In the code snippet we've got:



We are not 100% sure that there is only one entry in the Book table (or table has at least one entry at all).
Therefore this query may throw NoResultException or NonUniqueResultException!


Yes, the code may throw an exception, and you should never code this statement in a real program.

But in the exam, you have to answer the questions, which target entity manager in a Java SE environment.
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

What's wrong in #13? Where do we need an extra @Transient annotation?

Regards
 
Klaus Schultz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Krzysztof Koziol wrote:Hi there,

What's wrong in #13? Where do we need an extra @Transient annotation?


Has every not-annotated field type a default mapping? What is the default mapping of a Map<Integer,String> ?
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Klaus Schultz wrote:
Has every not-annotated field type a default mapping? What is the default mapping of a Map<Integer,String> ?



Thanks. Get it.
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Lievaart wrote:
Q27:
It is indeed a RuntimeException, so the bean is discarded.
The only reason I can think of that throwing an EJBException is not the correct answer,
is because in some cases a RemoteException is thrown.



I think it might happen when the business remote interface extends java.rmi.Remote. Then the java.rmi.RemoteException will be thrown instead of EJBException. Am I right?

Regards,
Krzysztof

 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Klaus Schultz wrote:
Yes, the code may throw an exception, and you should never code this statement in a real program.

But in the exam, you have to answer the questions, which target entity manager in a Java SE environment.



Thanks Klaus.

I didn't read the statement which says: "Assume [...] that there is a Book entity in the persistent store. ". Therefore it should work since there is only one entity.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Krzysztof Koziol wrote:

E Lievaart wrote:
Q27:
It is indeed a RuntimeException, so the bean is discarded.
The only reason I can think of that throwing an EJBException is not the correct answer,
is because in some cases a RemoteException is thrown.



I think it might happen when the business remote interface extends java.rmi.Remote. Then the java.rmi.RemoteException will be thrown instead of EJBException. Am I right?

Regards,
Krzysztof


No, the reason is that

Since the bean method is runs in the context of the client's transaction (as mentioned in Q27)
So, the container throw java.ejb.EJBTransactionRollbackException to client. If the business remote interface extends java.rmi.Remote, then the container throw java.transaction.TransactionRollbackException to client.

Note: If the bean method is runs in the context or the transaction that the container started (new transaction context)
then the container throw EJBException to client. If the business remote interface extends java.rmi.Remote, then the container throw RemoteException to client.

The above explanation apply for CMT


For BMT, the container throw EJBException to client. If the business remote interface extends java.rmi.Remote, then the container throw RemoteException to client. Because in BMT, bean method is surely runs in its own transaction context.



you may refer EJB Core spec 14.3.1, Table 14
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic