Creating a Java persistent entity |
This quick start shows how to create a new persistent Java entity. We will create an entity to associate with a database table. You will also need to add the ADDRESS table to your database.
Right-click the project in the Package Explorer and select New > Class. The New Java Class page appears.
On the Java Class page, enter a package name (such as quickstart.demo.model
), class name (such as Address
), and click Finish.
Right-click the Address.java
file in the Package Explorer and select Open.
Select the Address
entity in the JPA Structure view.
In the JPA Details view, in the Map As field, select Entity. In the Table field, select the ADDRESS database table.
Eclipse creates the persistent entity and adds the @Entity
annotation to the class.
Eclipse also displays the Address entity in the JPA Structure view:
After creating the entity, you must associate it with a database table.
Select the Address class in the Explorer view.
In the Persistence Properties view, notice that Dali has automatically associated the ADDRESS database table with the entity because they are named identically.
Note: Depending on your database connection type, you may need to specify the Schema. |
After associating the entity with the database table, you must update the persistence.xml
file to include this JPA entity.
Right-click the persistence.xml
file in the Package Explorer and select JPA Tools > Synchronize Classes. Dali adds the following to the persistence.xml
file:
<class>quickstart.demo.model.Address</class>
Now that you have created a persistent entity, you can continue with Mapping an entity to map the entity's fields to columns on the database table.