服务类:
@Service
@Transactional
public class MovieServiceImpl implements MovieService {
@Override
public void refreshAverageRating(Movie movie) throws DataAccessException {
movieRepository.refreshAverageRating(movie);
}
@Override
public void refreshAverageRating(Collection<Movie> movies) throws DataAccessException {
for (Movie movie : movies){
refreshAverageRating(movie);
}
}
}
存储库:
@Repository
public class MovieRepositoryImpl implements MovieRepository {
@Override
public void refreshAverageRating(Movie movie) throws DataAccessException {
.....
List<Rating> ratings = movie.getRatings(); ///fails here
.....
}
}
我无法理解为什么会出现异常。我认为@Transactional
应该提供会话。
是的,我了解fetchType.LAZY
是什么,不会将其更改为EAGER
。