==================================================================
这是类与表的映射文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.office2010.pojo">
<class name="Dept"  table="dept">
<id name="dept_id" column="dept_id">
<!-- 增长策略 -->
<generator class="identity"></generator>
</id>
<property name="dept_name" column="dept_name"></property>
<property name="dept_phone" column="dept_phone" ></property>
<property name="dept_fax" column="dept_fax"></property>
<property name="dept_describe" column="dept_describe"></property>
<many-to-one name="dept_parent" column="dept_parent" class="Dept" lazy="false"></many-to-one>
<set name="dept" lazy="false">
<key column="dept_parent"></key>
<one-to-many class="Dept"/>
</set>
<set name="users" lazy="false">
<key column="user_dept"></key>
<one-to-many class="User"/>
</set>
</class>
</hibernate-mapping>
========================================================
这是查询语句
public class DeptDaoImpl extends HibernateDaoSupport implements DeptDao {
/**
 * 查询顶级节点
 */
public List<Dept> selAll(){
System.out.println("222222222222222222222222222222222222222");
List<Dept> list=null;
Session session=this.getSessionFactory().openSession();
session.beginTransaction();
Query query=session.createQuery("from Dept");
list=query.list();
session.getTransaction().commit();
//List<Dept> list=this.getHibernateTemplate().find("from Dept");


// List<Dept> list=this.getHibernateTemplate().find("from Dept where dept_parent is null");
System.out.println("111111111111111111111122");
return list;
}}
并没有输出"111111111111111111111122"
=======================================
这是applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  
  <bean id="factory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
  </bean>
  <!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"  ref="factory"></property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="upt*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 指明那些类的那些方法需要代理 在bo中实现代理 -->
<aop:config>
<aop:pointcut id="doMethod" expression="execution(* com.office2010.boimpl.*.*(..))"/>
<aop:advisor pointcut-ref="doMethod" advice-ref="txAdvice"/>
</aop:config>
<!-- dao -->
 <bean id="attachdao" class="com.office2010.daoimpl.AttachDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
<bean id="deptdao" class="com.office2010.daoimpl.DeptDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
 <bean id="emailboxdao" class="com.office2010.daoimpl.EmailboxDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
 <bean id="emaildao" class="com.office2010.daoimpl.EmailDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
 <bean id="unitdao" class="com.office2010.daoimpl.UnitDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
 <bean id="userdao" class="com.office2010.daoimpl.UserDaoImpl">
  <property name="sessionFactory" ref="factory"></property>
 </bean>
 <!-- bo -->
 <bean id="attachbo" class="com.office2010.boimpl.AttachBoImpl">
  <property name="dao" ref="attachdao"></property>
 </bean>
 <bean id="deptbo" class="com.office2010.boimpl.DeptBoImpl">
  <property name="dao" ref="deptdao"></property>
 </bean>
  <bean id="emailbo" class="com.office2010.boimpl.EmailBoImpl">
  <property name="dao" ref="emaildao"></property>
 </bean>
  <bean id="eamilboxbo" class="com.office2010.boimpl.EmailboxBoImpl">
  <property name="dao" ref="emailboxdao"></property>
 </bean>
  <bean id="unitbo" class="com.office2010.boimpl.UnitBoImpl">
  <property name="dao" ref="unitdao"></property>
 </bean>
  <bean id="userbo" class="com.office2010.boimpl.UserBoImpl">
  <property name="dao" ref="userdao"></property>
 </bean>
 <!-- action的配置 -->
 <bean id="action" class="com.office2010.action.Action">
  <property name="userbo" ref="userbo"></property>
 </bean>
 <bean id="unitaction" class="com.office2010.action.UnitManagerAction">
  <property name="unitbo" ref="unitbo"></property>
 </bean>
 <bean id="deptaction" class="com.office2010.action.DeptManagerAction">
 <property name="bo" ref="deptbo"></property>
 </bean>
 <bean id="deptaddaction" class="com.office2010.action.DeptAddAction">
   <property name="bo" ref="deptbo"></property>
 </bean>
 <bean id="useraction" class="com.office2010.action.UserAction">
  <property name="bo" ref="userbo"></property>
  <property name="deptbo" ref="deptbo"></property>
 </bean>
</beans>
================================================
这是struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="actionaction" extends="struts-default">
<action name="action-*" class="action" method="{1}">
<result name="frameset">frameset.jsp</result>
<result name="fail">fail.jsp</result>
</action>
<action name="unitaction-*" class="unitaction" method="{1}">
<result name="unituptSuccess">unituptsucc.jsp</result>
<result name="unituptfail"></result>
</action>
<action name="deptaction-*" class="deptaction" method="{1}">
<result name="deptleft">deptleft.jsp</result>
</action>
<action name="deptadd-*" class="deptaddaction" method="{1}">
<result name="success">deptManager.jsp</result>
</action>
<action name="useraction-*" class="useraction" method="{1}">
</action>
</package>
</struts>
================================================
这是类public class Dept implements java.io.Serializable   {
//部门信息表
private int dept_id;
private String dept_name;
private String dept_phone;
private String dept_fax;
private String dept_describe;
private Dept dept_parent;
private Set<Dept> dept;
private Set<User> users;

public int getDept_id() {
return dept_id;
}
public void setDept_id(int dept_id) {
this.dept_id = dept_id;
}
public String getDept_name() {
return dept_name;
}
public void setDept_name(String dept_name) {
this.dept_name = dept_name;
}
public String getDept_phone() {
return dept_phone;
}
public void setDept_phone(String dept_phone) {
this.dept_phone = dept_phone;
}
public String getDept_fax() {
return dept_fax;
}
public void setDept_fax(String dept_fax) {
this.dept_fax = dept_fax;
}

public Dept getDept_parent() {
return dept_parent;
}
public void setDept_parent(Dept dept_parent) {
this.dept_parent =dept_parent;
}
public String getDept_describe() {
return dept_describe;
}
public void setDept_describe(String dept_describe) {
this.dept_describe = dept_describe;
}
public Set<User> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
this.users = users;
}
public Set<Dept> getDept() {
return dept;
}
public void setDept(Set<Dept> dept) {
this.dept = dept;
}

}
==========================================
把分全部押上了,希望各位大哥帮帮忙!!!!!!郁闷死了啊
==========================
希望各位帮帮忙如果有错误希望各位大哥能够给小弟指出来!!!

解决方案 »

  1.   

    没用spring 与struts 只用hibernate查询这个表时的报错信息为

    org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.office2010.pojo.User.user_paixu
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:85)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
    外键为空应该没问题啊
      

  2.   

    User.user_paixu这个属性是不是不能为空的?
      

  3.   

    你的一对多映射配置正确吗
    你的User.user_paixu 属性是否是非空
    你看下异常是在那一步产生的 都出异常了 还能打印什么?
    单步 一步一步看 
      

  4.   

    Null value was assigned to a property of primitive type setter of com.office2010.pojo.User.user_paixu
    你数据库总对应的字段应该是非空的吧?
      

  5.   

    User.user_paixu不知这个你是怎么定义的啊