休眠后选择空集合

时间:2014-06-14 18:11:19

标签: java hibernate

我想查找表格中的所有记录'用户'使用hibernate但它总是返回空集合(我确定有些用户在db中)。我的搜索功能如下:

    public List<Users> findAll() {
       DetachedCriteria criteria = DetachedCriteria.forClass(Users.class);
       return getHibernateTemplate().findByCriteria(criteria);
    }

为什么不工作?

hibernate.cfg.xml中:

<hibernate-configuration>
<session-factory>
  <property name="show_sql">true</property>
  <property name="format_sql">true</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/intellidom</property>
  <property name="connection.username">root</property>
  <property name="connection.password"></property>

  <mapping file="mapping/Users.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Users.hbm.xml:

<hibernate-mapping>
<class name="intellidom.entity.Users" table="users" schema="intellidom">
    <id column="id" name="id" type="int" >
        <generator class="increment"/>
    </id>
    <property name="login" column="login" type="java.lang.String"/>
    <property name="password" column="password" type="java.lang.String"/>
    <property name="firstName" column="firstName" type="java.lang.String"/>
    <property name="lastName" column="lastName" type="java.lang.String"/>
</class>
</hibernate-mapping>

0 个答案:

没有答案