Criteria.list()返回一个空集合,不执行任何查询

时间:2016-04-03 20:05:30

标签: java hibernate

我想获取Event.class对象的集合,但criteria.list()返回一个空集合。我也有show_sql = true属性,但是在控制台

中没有sql&#s

我的hibernate.cfg.xml

<hibernate-configuration>
  <session-factory>
    <!-- hibernate dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/inspector_database</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">********</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

    <!-- Simple memory-only cache -->
    <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
    <!-- <mapping class="mainobjects.Driver"/> -->
    <property name="hibernate.show_sql">true</property>
    <mapping class="inspectorserver.entities.Driver"  resource="inspectorserver/entities/Driver.hbm.xml"/>
    <mapping class="inspectorserver.entities.Event"  resource="inspectorserver/entities/Event.hbm.xml"/>
    <mapping class="inspectorserver.entities.Violation" resource="inspectorserver/entities/Violation.hbm.xml"/>
    <mapping class="inspectorserver.entities.Car" resource="inspectorserver/entities/Car.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Event.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 18.03.2016 21:32:29 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="inspectorserver.entities.Event" table="EVENT" lazy="false">
        <id name="id" type="java.lang.String">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="eventDate" type="java.lang.String">
            <column name="EVENTDATE" />
        </property>
        <property name="feeSum" type="java.lang.String">
            <column name="FEESUM" />
        </property>
        <property name="driverLicenseNumber" type="java.lang.String">
            <column name="DRIVERLICENSENUMBER" />
        </property>
        <property name="carVINCode" type="java.lang.String">
            <column name="CARVINCODE" />
        </property>
        <property name="syncStatus" type="int">
            <column name="SYNCSTATUS" />
        </property>


    </class>
</hibernate-mapping>

这就是我收藏的方式:

Session session = MyHibernateUtil.getSessionFactory().openSession();
Criteria criteria = session.createCriteria(Event.class);   
criteria.list(); //empty

1 个答案:

答案 0 :(得分:0)

通过删除class =&#34; inspectorserver.entities.Driver(Event等)来解决这个问题&#34;来自标签