EntityManager.flush()没有更新

时间:2017-10-16 17:18:33

标签: java jpa

我创建了一个名为Role的Entity类,并尝试更新Role表中的记录,但flush()方法没有更新记录。

以下是执行更新的方法:

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateRole(long appUserId, long roleId){
    EntityManager em=getEntityManager();
    TypedQuery<Role> query = em.createNamedQuery("Role.findRoleByUser", Role.class);
    query.setParameter("applicationUserId", appUserId);
    Role userRole= query.getSingleResult();
    userRole.setRoleId(roleId);
    em.merge(userRole);
    em.flush();
    em.detach(userRole);
    }

需要帮助才能找到问题。

更新-1: Role.java:

    @Entity
    @Table(name = "ROLE")
    @NamedQueries({
            @NamedQuery(name = "Role.findRoleByUser",
                    query = "select r from Role r where r.userId = :applicationUserId")
    })
    @XmlRootElement
    public class Role extends AuditInfo{

        public static final Long SYSTEM_USERID = 1000L;

        @Id
        @Column(name = "ROLE_ID")
        private long roleId;

        @Id
        @Column(name = "USER_ID")
        private long userId;


        public long getRoleId(){ return this.roleId; }

        public void setRoleId(long roleId) { this.roleId = roleId; }

        public long getUserId() { return this.userId; }

        public void setUserId(long userId) { this.userId = userId; }
}

0 个答案:

没有答案