JPA: persistence model

In this post we will create a persistence model for our little employee management application. Based on an earlier post where we created a basic JDeveloper Web application.

Over the project with contextual menu, New > EJB > Entities From Tables. We will use the EJB 3.0 technology, annotating entity beans as JPA 2.0:

Creating persistence model

Select Departaments and Employees tables.

As seen in an earlier post, we can obtain the ER diagram from a made data base. I created it in the package lebrijo.diagrams:

Entity-RelationShip diagram

We can create a New > EJB Diagram, and drag-drop the created entities, we have the whole draw:

EJB diagram

I refactored the employees attribute by manager, because it defines the relationship better.

Refactoring manage relation

This is refreshed automatically to the EJB diagram (theory, in practice I have to drag the entities again).

As last exercise, we can create the ‘find by name’ query, in the query annotation at Employees entity:

@Entity
@NamedQueries({
@NamedQuery(name = "Employees.findAll", query = "select o from Employees o")
,
@NamedQuery(name = "Employees.findByName", query = "select o from Employees o where o.firstName like :p_name")
})

Leave a Reply

Your email address will not be published. Required fields are marked *