This question is similar to the following:

What caused hibernate generate a update clause?

But it seems to not have answer

The log says the following is the update message. We are not explicitly doing this, however. Hibernate is somehow auto generating this upon a SELECT statement

update
        ops2.dbo.ObjectA
    set
        AcceptDate=?,
        ActionTaken=?,
        ModifyBy=?,
        ModifyByID=?,
        ModifyDate=?,
        ModifyDept=?,
        ParentId=?,
        Priority=?,
        RepRqmt=?,
        SchedDate=?,
        SchedDate=?,      
    where
        Rank=?

This is the statement that generates the problem:

  Query query =
            session.createSQLQuery("SELECT * FROM ProductOrders").addEntity(MyOrder.class);

        List<MyOrder> orders= query.list();
有帮助吗?

解决方案

By default, Hibernate flushes the pending changes before executing a query, to make sure that the query sees the changes that you've made before executing this query. If it didn't you could have this frustrating situation:

Foo foo = (Foo) session.get(Foo.class, 1L);
foo.setColor("red");
List<Foo> redFoos = 
    session.createQuery("select foo from Foo foo where foo.color = 'red'");
if (redFoos.isEmpty()) {
    System.out.println("WTF?");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top