This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

My exam cloud mock 4, @EntityListeners class  RSS feed

 
Ranch Hand
Posts: 1733
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: 3274
296
Android Chrome Eclipse IDE
  • 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)


 
Always look on the bright side of life. At least this ad is really tiny:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!