More Advanced Features APPENDIX A n n n (Web design templates)
More Advanced Features APPENDIX A n n n More Advanced Features APPENDIX A n n n In this appendix, we discuss some of the features that, strictly speaking, lie outside the scope of this book, but that you should be aware of if you go on to use Hibernate in more depth. EJB 3 and the EntityManager The third version of the Enterprise Java Beans specification, generally known as EJB 3, has recently been finalized. Among other features, EJB 3 includes a standard ORM technology that was significantly influenced by the design of Hibernate. You encountered this close relationship in Chapter 6 when we discussed Hibernate s use of the EJB 3 annotations for creating entity mappings. Annotations can be used throughout your EJB 3 applications to denote various settings. They are also used to mark for injection of resources from the container in a manner very like that of Spring s dependency injection (see Appendix C). HQL, which was discussed in Chapter 9, is very similar to the EJB QL used in EJB 3 environments generally speaking, your HQL queries can be used as EJB QL queries without change. Given these similarities, a Hibernate application can be converted into a portable EJB 3 application with surprisingly few changes. EJB 3 now supports both J2SE environments and those hosted within J2EE application servers; so even a stand-alone application can be written to take advantage of the EJB 3 features. The standard way to access the ORM components of an EJB 3 application is through the EntityManager. The Hibernate team provides appropriate libraries for download on their EntityManager site at http://entitymanager.hibernate.org. The EntityManager is configured through a standard file called persistence.xml, which must be provided in a META-INF directory accessible from the classpath (or, in a J2EE environment, from the root of the deployed archive). This file serves the same purpose as a conventional Hibernate configuration file (hibernate.cfg.xml), although its syntax is somewhat different. An example file is given in Listing A-1. Listing A-1. An EJB 3 persistence.xml Configuration File