日期:2014-05-19  浏览次数:20643 次

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="conf