Java Hibernate在更新行后返回错误的结果

Java Hibernate在更新行后返回错误的结果,java,hibernate,Java,Hibernate,我还是个冬眠新手,但我快疯了。问题是,在更新数据库中的某些实体之后,Hibernate无法返回这些更改。同时,使SQL查询返回旧值(与我从MySQLWorkbench获得的结果相比) 我认为这是一个缓存问题,但是在我的hibernate.cnf,xml中,我有以下几行代码禁用二线缓存。有人能解决那个问题吗?。我正在使用Hibernate v.4.3.1 conf文件如下所示: <property name="connection.pool_size">3</proper

我还是个冬眠新手,但我快疯了。问题是,在更新数据库中的某些实体之后,Hibernate无法返回这些更改。同时,使SQL查询返回旧值(与我从MySQLWorkbench获得的结果相比)

我认为这是一个缓存问题,但是在我的hibernate.cnf,xml中,我有以下几行代码禁用二线缓存。有人能解决那个问题吗?。我正在使用Hibernate v.4.3.1

conf文件如下所示:

    <property name="connection.pool_size">3</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
    <property name="hibernate.cache.use_second_level_cache">false</property>
    <property name="hibernate.cache.use_query_cache">false</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <property name="format_sql">false</property>
    <property name="show_comments">false</property>
}

更新


我使用的是GWT+RequestFactory+Hibernate,将RequestProxy EntityProxy更改为ValueProxy(因为我不需要EntityProxy)效果很好。这可能是RequestFactory的问题吗?

实际将实体写入数据库的代码在哪里?您是否已提交交易?是的,我已提交交易。事实上,如果我通过MysqlWorkbench直接向表中插入一行,Hibernate将无法刷新它。我已经更改了连接池(我使用的是内置池),现在它似乎工作正常。你需要什么代码?插入表格?
private static final SessionFactory sessionFactory;

static {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        Configuration configuration = new Configuration();
        configuration.configure();
        StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
                configuration.getProperties()).build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    sessionFactory.getCache().evictAllRegions();
    sessionFactory.getCache().evictEntityRegions();
    sessionFactory.getCache().evictCollectionRegions();
    sessionFactory.getCache().evictQueryRegions();
    return sessionFactory;
}