Spring @Transcational和“懒得初始化一个集合”

时间:2015-09-27 15:07:21

标签: java spring hibernate session service

服务类:

@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

0 个答案:

没有答案