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.
Creating a new entity instance in the context - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
Creating a new entity instance in the context
- [Instructor] Now it's time to create an instance of the book entity in the persistence context. I'm starting by setting this property in the persistence.xml file. Hibernate.show_sql and set it to true. This allows you to check what happens behind the scenes when hibernate performs different operations of the entity manager to work with the persistence context by logging SQL statements. Now that you have a book entity that corresponds to the book database table and which has ID, name, and ISBN fields that map to fields in that table, you should now be able to create a new book instance. So in the main class, create a new book instance like this. Book, let's call it book and new Book. We don't need to set a value for the primary key ID because we are using a generated value for it. So let's set a name and an ISBN to it. Book.setName. Let's call it my book. Book.setIsbn. Now you should tell the entity manager what we need to do with the new entity instance. You need to tell it to add…
Contents
-
-
-
-
-
-
Defining an entity3m 59s
-
(Locked)
Mapping entity fields to table columns3m 57s
-
(Locked)
Specifying the primary key4m 57s
-
(Locked)
Creating a new entity instance in the context5m 39s
-
(Locked)
Challenge: Art Class Management app, part 21m 10s
-
(Locked)
Solution: Art Class Management app, part 22m 27s
-
-
-
-
-
-