EJB
An EJB module must be individually loaded onto the server. Deployment is different from that for the usual war file.
How to create EJB
1. Creating Session Bean
• Use a NetBean EJB project to create EJBs
• Bean can be created using Java 5 or Java 6. It does not matter
• Bean can be created using J2EE 1.4 or 5. The differences are:
- NetBeans creates 2.1 compliant beans with J2EE 1.4 and EJB 3 beans with J2EE (using New->Session Bean on project)
- Client must use same version of J2EE libraries to access beans
The best way to create EJB is to use NetBeans’ built-in New->Session Bean function, which would create all the relevant class files and configuration files.
For EJB 2.1:
• Create interface class that defines a set of functions
• Create a bean implementation class derived from SessionBean object, implementation does not need to derive from the interface class even though it does implement the entire interface. See Head First EJB page 21.
• Create home interface by deriving from EJBHome, this is what the client use to get a reference to object. Create other interface classes.
• The EJB module does not need to include any J2EE jar
• Create ejb-jar.xml to identify the beans
• Create sun-ejb-jar.xml to specify the JNDI name.
• Upload module to server using server admin interface
For EJB 3.0:
• Create a set of base classes using NetBeans New->Session Bean wizard
• Code implementations and simply upload module to web server
2. Accessing Session Bean from standalone client
• See this Sun document for specify instruction:
http://docs.sun.com/source/819-0079/dgacc.html#wp1022132
• Use J2EE libraries appserv-rt.jar and j2ee.jar for J2EE 1.4
• Use same libraries plus javaee.jar, appserv-ext.jar, and appserv-deployment-client.jar for J2EE 5
• To run 1.4 client, follow instruction in link. Optionally set these environments either from the JVM –D parameter or set them through the context, for other than default values (localhost:3700):
jvmarg value = "-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"
jvmarg value = "-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"
• If client does not obtain an object of a correct class, there is an issue with the runtime jars
• To run 5 client, simply use the @EJB annotation to create an instance of the session bean. The instance must be of class Remote. Use InitialContext to do a lookup by class name
JPA is the next generation entity persistence technology
Demonstrate JPA from NetBeans
• Add jconn2.jar to C:\SUN\AppServer\domains\domain1\lib\ext
• Create driver in Databases under the Services tab
• Create JDBC connection in GlassFish server Connection Pools
• Use connection as template to create GlassFish connection pool using New->JDBC Connection Pool. Edit sun-resources.xml file to add missing properties (serverName and poolNumber)
• Create new connection using New->JDBC Resource, and use that to create classes using New->Entity Classes from Database
• Create new Persistence Unit with Java Transaction APIs
- generated persistence.xml file
JPA Implementation in general
JPA requires the use of a third party persistence provider. Among the currently available are TopLink, Hibernate, or openjpa. openjpa is not so good because of the buggy orm.xml parser (fails to handle [close] as a Sybase column name). Hibernate seems to be the most stable.
A project can only use annotation or XML. If xml-mapping-metadata-complete is specified, all annotations anywhere in the project are ignored.