带注释@Transactional的类服务不会更新数据库中的数据

时间:2017-12-02 21:17:26

标签: java spring hibernate spring-boot eclipselink

我有一个班级(短代码)(更多代码https://pastebin.com/m3wUwyHx

@Service("contributionPersistenceService")
@Transactional(rollbackFor = {...})
public class ContributionPersistenceServiceImpl implements ContributionPersistenceService {
...
@Override
public void createOtherTitleContribution(
        ContributionNew<OtherTitle> contribution,
        Long movieId,
        Long userId
) {
    final List<MovieOtherTitle> otherTitlesEntities = movie.getOtherTitles().stream()
            .filter(otherTitle -> otherTitle.getStatus() == EditStatus.ACCEPTED).collect(Collectors.toList());

   contribution.getIdsToDelete()
            .forEach(id ->
                    this.setReportedForDelete(otherTitlesEntities, id)
            );
}
...
public void setReportedForDelete(final List<? extends MovieInfo> enties, final Long id) {
    enties.forEach(entity -> {
        if(entity.getId() == id) {
            entity.setReportedForDelete(true);
        }
    });
}
}

问题在于,当我想更改实体的值reportedForDelete时,它不会保存到数据库中。

只有这样的命令出来。

    [EL Fine]: sql: 2017-12-02 22:00:39.016--ClientSession(2007386597)--Connection(1901834254)--SELECT ID, activation_token, EMAIL, email_change_token, ENABLED, modified_date, new_email, PASSWORD, registration_date, USERNAME, UUID FROM users WHERE ((ID = ?) AND (ENABLED = ?))
    bind => [2 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.024--ClientSession(2007386597)--Connection(1901834254)--SELECT ID, BUDGET, RATING, STATUS, TITLE, TYPE FROM movies WHERE ((ID = ?) AND (STATUS = ?))
    bind => [2 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.03--ClientSession(2007386597)--Connection(1901834254)--SELECT ID, dtype, REPORTEDFORDELETE, REPORTEDFORUPDATE, STATUS, MOVIE_ID, USER_ID, other_title_country, other_title FROM movies_info WHERE ((MOVIE_ID = ?) AND (dtype = ?)) ORDER BY ID ASC
    bind => [2 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.079--ClientSession(2007386597)--Connection(1901834254)--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
    bind => [2 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.082--ClientSession(2007386597)--Connection(1901834254)--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
    bind => [1 parameter bound]
[EL Fine]: sql: 2017-12-02 22:00:39.21--ClientSession(2007386597)--Connection(1901834254)--INSERT INTO contributions (ID, creation_date, FIELD, STATUS, user_comment, verification_comment, verification_date, MOVIE_ID, USER_ID, verification_user) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [10 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.217--ClientSession(2007386597)--Connection(1901834254)--INSERT INTO contributions_ids_to_delete (contribution_id, element_id_to_delete) VALUES (?, ?)
    bind => [2 parameters bound]
[EL Fine]: sql: 2017-12-02 22:00:39.219--ClientSession(2007386597)--Connection(1901834254)--INSERT INTO contributions_sources (contribution_id, SOURCES) VALUES (?, ?)
    bind => [2 parameters bound]

MovieInfo实体表没有UPDATE命令。

注释@Transactional的工作方式使得在实体中编辑的任何内容都会在数据库中自动更新,并且在此处不起作用。

我尝试在编辑后立即保存对象,但它也不会更改数据库中的字段。

if(entity.getId() == id) {
            entity.setReportedForDelete(true);
            this.entityManager.persist(entity);
        }

0 个答案:

没有答案