From the course: Learning Java Enterprise Edition

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

JPA in practice: Repository

JPA in practice: Repository - Java EE Tutorial

From the course: Learning Java Enterprise Edition

Start my 1-month free trial

JPA in practice: Repository

- [Instructor] Now, let's have a look at where we are using this entity and interacting with the data store. Open up the DefaultBookingService and notice that we have a CargoRepository injected here. This bean contains all the methods necessary to persist a Cargo object, retrieve a Cargo object, and execute various queries against the cargo database. Let's scroll down and have a look at some of the methods. The first method we meet is the bookNewCargo method. This method is responsible for booking a new cargo into the system and persisting it into the database. Let's scroll down and have a look at where we do this. What we're doing here is we're passing the cargo entity that we have constructed through to the store method of the cargoRepository. Let's have a look at that method. This method is a method on the JpaCargoRepository. As you can see, what this method does is it simply takes the Cargo object and persist it into the database. It does this by calling the persist method on the…

Contents