From the course: Java EE 8 Essential Training

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Entity mapping

Entity mapping

- [Instructor] JPA providers use entity annotations to determine how to persist our entities to a database. Let's take a look at some of these annotations and map one of our entities. So here we have the catalog item class. It's just a basic POJO and we're going to turn this class into an entity by just adding the entity annotation. Another class-level annotation that we can add to our entities is the table annotation, and this allows us to specify the name of the table within the relational database that corresponds with this entity. So there you can see we are mapping the catalog item class to the catalog_item table within our database. Now we can move onto the field-level annotations, so we're going to use the ID annotation to indicate that the item ID is our primary key on this entity, and we can go ahead and specify the column name here. We'll just call this the catalog item underscore ID column. You'll notice it…

Contents