Aug 16, 10 by Juan Lebrijo about Oracle, Java, JDeveloper, blog
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:
create_persistence_model.png114 KB
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:
er_diagram.png157 KB
We can create a New > EJB Diagram, and drag-drop the created entities, we have the whole draw:
ejb_diagram.png119 KB
I refactored the employees attribute by manager, because it defines the relationship better.
refactor_manager.png79.9 KB
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")
})