Menu

Create an Entity

Ralph

An entity represents an image of a database table to the Java program. An entity is under control of the persistence unit and fill be maintained by EclipseLink.

Create a simple entity:

package de.hoppe.extra.model;

import ...

/**
 * The persistent class for the PERSONEN database table.
 */
@Entity
@Table(name = "PERSONEN")
@NamedQueries({ @NamedQuery(name = "Person.getAll", query = "SELECT p FROM Person p ORDER BY p.search"),
    @NamedQuery(name = "Person.getBySearch", query = "SELECT p FROM Person p WHERE p.suche LIKE :search ORDER BY p.search"),
    @NamedQuery(name = "Person.getUsers", query = "SELECT p FROM Person p WHERE p.dbUsername IS NOT NULL AND p.search LIKE :search ORDER BY p.search") })

public class Person extends de.hoppe.fxDb.persistence.Entity
    implements Serializable, de.hoppe.fxDb.persistence.IEntity {

  private static final long serialVersionUID = 1L;

  @Id
  @SequenceGenerator(name = "PERSONEN_ID_GENERATOR", sequenceName = "PERS_SEQ", allocationSize = 5)
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PERSONEN_ID_GENERATOR")
  @Column(unique = true, nullable = false)
  private Long id;

This entity is only a template. Please read the JPA and EclipseLink documentation how to create an entity.
The important part is to extend the fxDb.persistence.Entity.

This entity is necessary to access objects from the database.
An entity is not used to display values in a form or in a list of records.
For this we introduce a new class type named View Object.


Next step is to [Create a View Object].


Related

Wiki: Create a Connection Identifier
Wiki: Create a View Object