From the course: Java EE 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
EntityManager basics - Java EE Tutorial
From the course: Java EE 8 Essential Training
EntityManager basics
- [Instructor] In order to persist entities within our application, we'll need to work within EntityManager. The EntityManager exposes operations that allows us to perform CRUD operations against our data store. We're going to be working with the EntityManager within our EJB. So here we have the Catalog EJB we created and you'll see right now, it's pretty much using this list for persistence. We're going to change that in this lesson. So the first thing that we're going to do is inject our EntityManager using the PersistenceContext annotation. And we apply that to a field of type EntityManager and that will cause the container to inject an EntityManager that we can use for performing persistence operations. Now, you'll notice we have our two methods. One gets the items, the other adds an item. So let's first add the logic to pull all of our CatalogItems using the EntityManager. And to do that, we use the createQuery…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.