读书人

mysql数据中存在数据用hibernate能掏

发布时间: 2012-07-16 15:44:59 作者: rapoo

mysql数据中存在数据,用hibernate能取出数据,但在mysql命令行中取出的数据为空
我的实体类:

Java code
package domain;import java.util.HashSet;import java.util.Set;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.Table;/** * 分类(顶级版面) * @author wn * */@Entity@Table(name="t_category")public class Category {        private int id;    private String name;    private int category_order;        /**     * 分类(顶级版面)中的子版面(二级版面)     * 1-N关联关系,用Set来保存关联实体     *///    private Set<Forum> forums=new HashSet<Forum>();        @Id    @GeneratedValue    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    //    public Set<Forum> getForums() {//        return forums;//    }//    public void setForums(Set<Forum> forums) {//        this.forums = forums;//    }        public int getCategory_order() {        return category_order;    }    public void setCategory_order(int category_order) {        this.category_order = category_order;    }    @Override    public int hashCode() {        final int prime = 31;        int result = 1;        result = prime * result + id;        return result;    }    @Override    public boolean equals(Object obj) {        if (this == obj)            return true;        if (obj == null)            return false;        if (getClass() != obj.getClass())            return false;        final Category other = (Category) obj;        if (id != other.id)            return false;        return true;    }                }

hibernate.cfg.xml配置
XML code
<!DOCTYPE hibernate-configuration PUBLIC    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>         <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:3306/mybbs2</property>         <property name="hibernate.connection.username">root</property>         <property name="hibernate.connection.password">123456</property>         <property name="hibernate.hbm2ddl.auto">update</property>         <property name="hibernate.show_sql">true</property>         <property name="hibernate.format_sql">true</property>         <mapping class="domain.Category"/>              </session-factory></hibernate-configuration>


applicationContext.xml配置
XML code
<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://www.springframework.org/schema/beans"    xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        <property name="configLocation" value="classpath:hibernate.cfg.xml" />     </bean>             <bean id="categoryDao" class="dao.impl.CategoryDaoImpl" scope="singleton">        <property name="sessionFactory">            <ref bean="sessionFactory"/>        </property>    </bean>    <bean id="categoryService" class="service.impl.CategoryServiceImpl" scope="singleton">        <property name="categoryDao" ref="categoryDao"></property>    </bean>    <bean id="categoryAction" class="action.CategoryAction" scope="prototype">        <property name="categoryService" ref="categoryService"></property>    </bean>                </beans> 


情况:
页面能取到数据:


mysqlcommand cline client却取不到数据:

mysql> select * from t_category;
Empty set (0.00 sec)

是不是我哪里搞错了。请有经验这指点。

[解决办法]
页面取到的是缓存数据
=============================
页面能取到数据:


mysqlcommand cline client却取不到数据:

mysql> select * from t_category;
Empty set (0.00 sec)
=============================

再次添加数据时,原来的数据不见了。但是id却是在原来的基础上递增的。 //说明ID是自增的

读书人网 >J2EE开发

热点推荐