Merge pull request #12494 from hkhan/JAVA-13294-sync-code-with-article

[JAVA-13294] Add missing code for article
This commit is contained in:
kwoyke 2022-07-15 09:08:31 +02:00 committed by GitHub
commit 33d3612c66
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);
}
}