Merge pull request #12494 from hkhan/JAVA-13294-sync-code-with-article
[JAVA-13294] Add missing code for article
This commit is contained in:
commit
33d3612c66
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue