Mysql 事务方法不在数据库上写入更新

Mysql 事务方法不在数据库上写入更新,mysql,spring,hibernate,sql-update,entitymanager,Mysql,Spring,Hibernate,Sql Update,Entitymanager,我正在开发一个Spring应用程序,它使用Hibernate4.3管理MySql数据库中存储的数据 我只想更新此对象的值: @Table(name = "CONTENT") public class KcContent { @Id @GeneratedValue @Column(name = "ID") @DocumentId private Long id; @Column(name="PRIORITY") private Long

我正在开发一个Spring应用程序,它使用Hibernate4.3管理MySql数据库中存储的数据

我只想更新此对象的值:

@Table(name = "CONTENT")
public class KcContent {

    @Id
    @GeneratedValue
    @Column(name = "ID")
    @DocumentId
    private Long id;

    @Column(name="PRIORITY")
    private Long priority;

    // getter and setter
}
这是我更新对象的点:


private EntityManager entityManager;

@Transactional
public String checkAndManageActionsNewsletter(NewsletterActionRequestBean requestBean) {
    List<String> newsIds = requestBean.getNewsIds();

    // update priority based on position in list
    for(long priority = 0; priority < newsIds.size(); priority++) {
        String newsId = newsIds.get((int) priority);
        long contentId = Long.parseLong(newsId);
        KcContent news = getServiceCatalog().getContentService().find(contentId);
        news.setPriority(priority);
    }
}

为什么是链式的getter?您应该只是将
ContentService
注入bean中(您不应该知道内部结构)。
find
方法还有什么作用?请添加它。链式getter在那里,因为代码是由不了解Spring的人编写的。。。。不幸的是,我现在不能注入字段(由于缺乏时间,项目非常庞大)。我添加了find方法的实现。以及
getEntityManager
?为什么不呢?向这个类添加一个字段并没有那么多工作,您不需要更改整个代码库吗?另外,如果您的代码中有
entitymanager
(但您显然没有使用它),为什么要使用
find
。我不会直接使用
find()
方法,因为服务中已经提供了该方法。这里的要点是更新没有完成,并且
entityManager
设置正确。除了更好的设计之外,你认为这可能是一个问题吗?在这种情况下,这会产生怎样的影响?一件事是,
find
readOnly
,这可能会影响事务性。接下来是
getEntityManager
返回相同的实体管理器还是创建一个?初始方法是如何调用的?
public EntityManager getEntityManager() {
    return entityManager;
}

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
}

@Override
@Transactional(readOnly=true)
public KcContent find(Long id) {
    if (id == null){
        return null;
    }
    return getEntityManager().find(KcContent.class, id);
}