Java Reference
In-Depth Information
The EntityManager is used to query entities using a Query object created from a
named query:
Query query = em.createNamedQuery("findAllBlogsByName");
The named query parameters are set using the setParameter() method:
query.setParameter("blogName", "Smythe");
A SELECT query is run using the getResultList() method. A SELECT query that
returns a single result is run using the getSingleResult() method. An UPDATE
or DELETE statement is run using the executeUpdate() method. For a query
that returns a list, the maximum number of results may be set using the
setMaxResults() method.
List blogs=query.getResultList();
A persistence unit defines a set of entities that are mapped to a single database and
managed by an EntityManager . A persistence unit is defined in the persistence.
xml deployment descriptor, which is packaged in the META-INF directory of an
entity bean JAR file. The root element of the persistence.xml ile is persistence ,
which has one or more persistence-unit sub-elements. The persistence-unit
element consists of the name and transaction-type attributes and subelements
description , provider , jta-data-source , non-jta-data-source , mapping-file ,
jar-file , class , exclude-unlisted-classes , and properties . Only the name
attribute is required; the other attributes and subelements are optional. The jta-
data-source and non-jta-data-source are used to specify the global JNDI name
of the data source to be used by the persistence provider. For all the elements in the
persistence.xml and a detailed discussion on Java Persistence API, refer to the EJB
3.0 specification (ejb-3_0-fr-spec-persistence.pdf).
An interceptor is a method that intercepts a business method invocation or a lifecycle
callback event. In EJB 2.x, runtime services such as transaction and security are
applied to bean objects at the method's invocation time, using method interceptors
that are managed by the EJB container. EJB 3.0 has introduced the Interceptor feature
with which the interceptors may be managed by a developer. EJB interceptors are
methods annotated with the @javax.ejb.AroundInvoke annotation. Interceptors
may be used with business methods of session beans and message-driven beans.
Interceptor methods may be defined in the bean class or an external interceptor class
with a maximum of one interceptor method per class.
Search WWH ::

Custom Search