From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Mapping entity fields to table columns

Mapping entity fields to table columns - JPA Tutorial

From the course: Java Persistence with JPA and Hibernate

Mapping entity fields to table columns

- [Instructor] A class annotated with an @ entity annotation specifies that it models a database table or an entity. This means its fields should also map to the columns in the table. How is it possible to do that? Once again, annotations to the rescue. You should already have the library database created. So go to SQLTools, mariadb, and the library database is there. If not, simply run the mariadb init SQL script to set it up. Now, in the book table, if you describe the table by right clicking on it and selecting Describe table, there are three columns, book_id, book_name, and isbn. These need to be mapped to fields in the book class. So in the book class, there has to be three fields, id, name, and isbn. So let's go ahead and add them. Private int id, private String name, and private String isbn. Let's add getters and setters for them as well. Right click, Source Action, Generate Getters and Setters. And select all the fields and click on OK. Now, coming back to the fields, the…

Contents