• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

My exam cloud mock 4, @EntityListeners class

 
Ranch Hand
Posts: 1749
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


@Entity
@EntityListeners(com.epracticelabs.OrderMonitor.class)
public class Order{

@PrePersist
protected void validate(){//more code here....}
}
Which statement is correct?
A. The validate method may Not throw runtime exceptions.
B. The validate method can invoke the EntityMnager.flush operation.
C. Methods of the class com.epracticelabs.OrderMonitor annotated with callback annotations must take an Object or Order instance as the only argument.
D. The above class definition is NOT correct. An entity cannot define a callback method like PrePersist and use the EntityListeners annotation at the same time.
Given answer :C
Explanation:
EntityListeners specified the callback listener classes to be used for an entity or mapped superclass. This annotation may be applied to an entity class or mapped superclass. Methods of the EntityListeners annotated with callback annotations must take an Object or Account instance as the only argument.


Based on the following statements in the spec, none of the options above are correct.
Spec 3.5.1 Lifecycle callback methods    
callback methods defined on an entity class or mapped superclass have the following signature:
void <METHOD> ()
Since the class is marked as both @Entity and @EntityListeners, C is not correct.

Spec : 3.5 Entity Listeners and callback methods
The following rules apply to lifecycle callbacks:
- lifecycle callback methods may throw unchecked or runtime exception.... (A is not correct)
-In general the lifecycle method of a portable application should not invoke EntityManager or Query operations.... (B is not correct)

 
Creator of Enthuware JWS+ V6
Posts: 3293
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is correct.

Note that OrderMonitor is the EntityListener class and the following rule applies:

Callback methods defined on an entity listener class have the following signature:void <METHOD>(Object)


 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!