Enter a name say 'EARProject1', choose a JEE5 server (* At the time of writing we were unable to find any servers that would work with the new facets as they require server adapter plugins in WTP to work with the new facets, we chose an internal test server)as the Target Runtime, Click Next.

You can configure Facets here and bind to the runtime. Notice the new facet level 5.0 for creating JEE applications. As well as target it to a Java EE5 server.

Hit
Finish.after the wizard finishes, if you are not already in the J2EE
perspective, you will be prompted to switch agree by selecting
'Yes'. In the J2EE perspective you will see the EARProject in the
Project Explorer.

Now choose File > New > Other > EJB > EJB Project.
Enter a name EJBProject1, make sure you add it to the Ear
created in the earlier step.

Go to next Page ie the Project Facets page. Here you should see EJB facet version 3.0 selected, also select the JPA facet. Hit Finish.

Now, you should see the modules represented under in the Project Explorer.

Go to Window-Preferences-Connectivity-Driver Definitions and add a driver to a relational database to be used in the application.

Right Click on the EJB project and choose Generate Entities

That launches the JPA 'Generate Entities' wizard. Add a connection to a sample database. Provide a name and choose the Database driver created earlier. Also provide connection details. (see below)

Choose the connection and a schema and go to the next page, here choose a table

Hit Finish. This creates an entity bean in the project.

Now switch to the JPA perspective and open the entity bean in a java editor.

As you see you can edit properties of the bean using the JPA details view. I made some changes like specifying explicitly the table,schema, id column (defaults should work fine).

Now open the file persistence.xml and add the entity bean (* Adding the bean shouldnt be required, I think when we created the bean, the bean class entry should have been added to the file)and the jdbc data source used by the persistence unit.

As you see we are creating a instance variable of type EnitityManagerFactory (injecting is the JEE term), this variable is initialized by the server container at runtime. Using it we can access the entity bean. For example in the above code we have queried the database for all available beans of type Department.

Save the servlet. Your application is ready.

Create a datasource on the server with name=jdbc/MyDataSource, Run the application on server (*
We were unable to do that for now as that would have required server
adapters to work with new JEE facets, For now, we think we can write an ant script to generate a ear file out of the projects and deploy it on a server outside WTP)