[JAVA-13294] Add missing code for article

This commit is contained in:
Haroon Khan 2022-07-14 17:07:04 +01:00
parent 3db189f71a
commit 3fda2ec694
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package com.baeldung.hibernate.operations;
import com.baeldung.hibernate.pojo.Movie;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
public class MovieService {
@PersistenceContext
private EntityManager entityManager;
public void saveMovie() {
entityManager.getTransaction()
.begin();
Movie movie = new Movie();
movie.setId(1L);
movie.setMovieName("The Godfather");
movie.setReleaseYear(1972);
movie.setLanguage("English");
entityManager.persist(movie);
entityManager.getTransaction()
.commit();
}
public Movie getMovie(Long movieId) {
return entityManager.find(Movie.class, movieId);
}
}