Create entity

  1. In the menu, select File > New > Entity.

  2. At Entity > Name enter the name of the new Entity

  3. Click on Finish.
    image not found

  • Naming of entities - Entities are usually named in singular, e.g. Customer, while database tables are usually named in plural, e.g. Customers.

  • Besides the Entity itself, a new Data Access Object (DAO) is generated for the Entity.

Parameters

  • Entity - Settings for the new entity.

  • Data Access Object - Settings for the new DAO (Data Access Obect) for the Entity.

Result

  • Project Management > main-java > domain - The new entity class is generated here.

  • Project Management > main-java > dal - The DAO class for the new entity is generated here.

    image not found

Example

Generated code for a new Customer entity and CustomerDAO object:

  • Entity

@Entity
@DAO(CustomerDAO.class)
@Cacheable(true)
@Table(name = "Customer")
public class Customer implements Serializable
{
    private int id;

    public Customer()
    {
        super();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    public int getId()
    {
        return this.id;
    }

    public void setId(final int id)
    {
        this.id = id;
    }
}
  • DAO

public class CustomerDAO extends JpaDataAccessObject.Default<Customer, Integer>
{
    public final static CustomerDAO INSTANCE = new CustomerDAO();

    public CustomerDAO()
    {
        super(Customer.class);
    }
}

Entities can easily be edited in Entity Editor
image not found

  • Attribute - When adding attributes such as name, the Get method getName and the Set method setName are generated in the entity class in addition to the variable name, which are used to access the variable name. The get and set methods are called getter and setter.

private String name;

@Column(name = "`name`")
public String getName()
{
    return name;
}

public void setName(String noname)
{
    this.name = noname;
}
  • Int or Integer - It is recommended to use type classes like Integer for the attributes of your entities, since primitive data types like int cannot take a null value, which is however commonly used in relational databases.

  • Missing Java data types - For the Java data types used in the entities, appropriate database data types are automatically used when generating the database.

  • Changes to source code are detected - Entity Editor allows you to work bidirectionally. After every single change you make in the Entity Editor, the source code is automatically adjusted. Conversely, after changes are made to the source code, the Entity Editor is automatically updated.