문제

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