Oracle has built some extensions to its EJB 3 implementation in Oracle Application Server 10.1.3.1 to simplify developers' life. In this blog I will uncover these extensions.
Vendor Specific Annotations
We have added three proprietary annotations @StatelessDeployment, @StatefulDeployment and @MessageDrivenDeployment that you can use to specify Oracle specific configurations for your bean. This frees you from having to deal with vendor specific descriptor. For example, you can use the @StatelessDeployment annotation to specify pooling information for an EJB as follows:
import oracle.j2ee.ejb.StatelessDeployment;
@StatelessDeployment(minInstances = 100, maxInstances = 500)
@Stateless
public class HelloBean implements Hello {
..
}
Additionally we have provided annotations to be used with EJB 3 web services (that use web services metadata annotations) : @Deployment, @Schema, @WSIFEJBBinding, etc. The @Deployment annotation is most important annotation of these and can be used to specify portName, contextPath or expose the web service as a REST web service.
For example:
@Deployment(contextPath="ejb30", uriPath="ejb30-simple", portName="MyWebService")
@WebService
@Statelesspublic class HelloBean{
..
}
You can refer to the Oracle Annotations Java Doc for details about these annotations.
Simplification to Use JPA inside container
We have added several small knobs here and there to simplify use of JPA inside container.
persistence.xml is optional in EJB Modules
JPA requires persistence.xml for configuring a persistence unit. This is really a headache for developers when using entities in an EJB module and has only one persistence unit. Oracle Application Server makes it optional and will search for entities in the ejb-jar and configure a default persistence unit for you. The data-source will be defaulted to the default data source configured for the application or server. This will also help customers using EJB 3 in OracleAS 10.1.3.0 to migrate to OracleAS 10.1.3.1 easily.
Using @Resource annotationInjecting container-managed EntityManager
Many developers have asked why can’t they use @Resource annotation to inject a container managed EntityManager? It seems really odd that you can inject other resources such as DataSource but not EntityManager. The real answer is EntityManager is not a resource and you may have more than one persistence unit. If you have only one persistence unit in your application OracleAS has extension to support injection of EntityManager using @Resource as follows:
@Resource EntityManager em;
This also helps customer to migrate their applications to OracleAS 10.1.3.1 from earlier release.
persistence.xml in WEB-INF
If you have used entities in the web module then you know that Java EE 5 requires packaging of persistence.xml in the WEB-INF/classes/META-INF directory. It is really confusing for developers because all descriptors for web module are placed in WEB-INF directory. Why not persistence.xml you may ask? There is a real reason (and there was hot discussion in the EJB3 expert group) for this that I will discuss in a future blog. However it is worth mentioning here that OracleAS makes it simple and allow packaging of persistence.xml in WEB-INF/ directory and if found it will be considered to similar to packaging it in WEB-INF/classes/META-INF directory.
Hope these extensions make your life easier. If you have an idea for a feature that you would like to see in OracleAS do not hesitate to send that to me.
No comments:
Post a Comment