简体   繁体   English

休眠:表未更新

[英]Hibernate : Table doesn't get updated

I'm having trouble with my hibernate transaction. 我在休眠交易时遇到了麻烦。 After execution , table has no values in it and is not updated at all. 执行后,表中没有任何值,也不会更新。 All my other updates work properly. 我所有其他更新均正常运行。

Here's the mapping 这是映射

 <class name="LastDownloadedMessage" table="t_imap_lastmsguid">
    <id name="id" column="id" ><generator class="increment"/></id>
    <property name="lastDownloadedMessageUid"><column name="last_msg_uid" /></property>
    <property name="lastUidNext"><column name="next_msg_uid" /></property>
    <property name="folder"><column name="folder_name" /></property>
     <property name="cred"><column name="credential" /></property>
 </class>

This is the POJO object : 这是POJO对象:

public class LastDownloadedMessage {
    Integer id;
    private String lastDownloadedMessageUid;
    private String lastUidNext;
    private String folder;
    private String cred;

    //GETTERS AND SETTERS HERE

    public LastDownloadedMessage() {
        super();
    }
    public LastDownloadedMessage(String lastDownloadedMessageUid,
            String lastUidNext) {
        super();
        this.lastDownloadedMessageUid = lastDownloadedMessageUid;
        this.lastUidNext = lastUidNext;
    }
}

and this is the function which is doing the update. 这就是进行更新的功能。

    Session ssn=HibernateSessionFactory.openSession();
    Transaction txn = ssn.beginTransaction();
    Query query = ssn.createQuery("update LastDownloadedMessage e set e.lastDownloadedMessageUid = :luid , e.lastUidNext = :nextUid where e.folder =:folder and e.cred = :cred");
    query.setParameter("luid",last_downloaded_msg_uid);
    query.setParameter("nextUid", uid_next);
    query.setParameter("folder", folder);
    query.setParameter("cred", credential);
    int result = query.executeUpate();
    txn.commit();
    ssn.flush();
    ssn.close();

The function appears to execute properly with no errors . 该功能似乎正常执行,没有错误。 What could be the issue ? 可能是什么问题 ?

Based on the comments, it seems to me you are confusing UPDATE with INSERT. 根据评论,在我看来,您正在将UPDATE与INSERT混淆。 If result is zero, it means your WHERE clause didn't match anything, so there's nothing to update. 如果result为零,则意味着您的WHERE子句不匹配任何内容,因此没有任何要更新的内容。

Also, why are you trying to issue an UPDATE/INSERT on a known (mapped) entity? 另外,为什么要尝试在已知(映射)实体上发出UPDATE / INSERT? All you have to do is set your values on your object (LastDownloadedMessage) and then execute a persist on your EntityManager. 您所要做的就是在对象(LastDownloadedMessage)上设置值,然后在EntityManager上执行persist Browse around the web for EntityManager.persist . 在网上浏览EntityManager.persist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM