Create entity

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

  2. At Entity > Name enter the name Automaker.

  3. Click on Finish.

    image not found

Note:

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

  • Data Access Object - The settings at * Data Access Object* can be used to create a Data Access Object (DAO) with the same name for this entity.

  • Persistence Unit - The Persistence Unit is generated automatically.

Parameters:

Result:

  • Project Management - Under main-java > domain the class Customer and under main-java > dal the class CustomerDAO is created.

    • *Customer

      @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;
          }
      }
    • *CustomerDAO

      public class CustomerDAO extends JpaDataAccessObject.Default<Customer, Integer>
      {
          public final static CustomerDAO INSTANCE = new CustomerDAO();
      
          public CustomerDAO()
          {
              super(Customer.class);
          }
      }
  • Entity Editor - In the entity editor, the new entity Customer is displayed and can be edited.
    image not found

Tips:

  • 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.