Hibernate保留旧数据

时间:2014-07-28 09:49:42

标签: mysql spring hibernate java-ee

我是Hibernate和Spring MVC的初学者,我在检索数据时遇到了重复的问题,有时当我刷新页面或只是提交表单时,我会得到我已更新甚至删除的旧数据。

这是我的hibernate配置文件:

<hibernate-configuration>
<session-factory>
 <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/cotaDB18</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</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.NoCacheProvider</property> -->

    <property name="hibernate.connection.isolation">4</property>

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

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

</session-factory>

我检索这样的数据:

@SuppressWarnings("unchecked")
@Override
public List<Tache> getTachesByPhase(int idPhase) {
    Session session =  HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    String hql = "From Tache T where T.phase=" + idPhase + " Order by T.index";
    Query query = session.createQuery(hql);
    return query.list();
}

我需要你的帮助,我找不到解决方案

0 个答案:

没有答案