Tag Archives: JDeveloper

JPA: modelo de persistencia

En este artículo crearemos un modelo de persistencia para nuestra pequeña aplicación de gestión de empleados. Basado en un anterior post donde creamos una aplicación básica de JDeveloper.

Sobre el proyecto en el menú contextual, New > EJB > Entities From Tables. Vamos a utilizar la tecnología EJB 3.0, anotando los beans de entidad como JPA 2.0:

Creating persistence model

Seleccionamos las tablas Departaments y Employees.

Como vimos en un artículo anterior, se puede obtener el diagrama de una base de datos ya hecha. Yo me lo he creado en el paquete lebrijo.diagrams:

Entity-RelationShip diagram

Podemos crear un New > EJB Diagram, y arrastrando las entidades anteriormente creada, tendremos el dibujo entero:

EJB diagram

En los dos beans refactorizaré el atributo employees por manager, ya que define más claramente la relación.

Refactoring manage relation

Esto se actualiza automáticamente en el diagrama de EJB (en teoria, en realidad hay que volver a arrastrar las entidades).

Como último ejercicio, podemos crear la consulta de encontrar por nombre, ampliando la anotación de consultas de la entidad Employees:

@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")
})

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")
})

Weblogic / JDeveloper: Creating the base application

Open JDeveloper with “Default role” option, to activare al environment features. We are interested in JEE and database development features.

File > New > Java EE Web Application, then we are creating the new application estructure:

Creating app

Put the name “HRApplication”, and it creates two projects on the app:

  • ViewController: contains the view of our application, which corresponds with ADF technology based on JSF standard.
  • Model: contains EJB session beand and JPA entities.

To create a database connection go to the “Database Navigator” tab, and with right buton> New, introduce the connection configuration:

Creating db connection

Drag and drop the connection to our application:

Adding HR connection to our application

Then we are ready to start modeling and programming.