日期:2014-05-20  浏览次数:20844 次

hibernate问题:net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of com.Customer.name
类的xml映射文件内容如下: 
<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping 
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> 
<hibernate-mapping package="com.xxxx"> 
  
  <class name="Customer" dynamic-insert="true" dynamic-update="true" table="CUSTOMERS"> 
  <id name="id"> 
  <generator class="increment"/> 
  </id> 

  <property name="name"/> 
  <property name="sex" access="field" /> 
  <set name="orders" inverse="true" cascade="save-update">  
  <key column="CUSTOMER_ID" /> 
  <one-to-many class="Order" /> 
  </set> 

  <property name="description" type="string" column="DESCRIPTION"/> 
   
  </class> 
</hibernate-mapping> 

通过程序执行查询: 
  Session session = sessionFactory.openSession(); 
  Transaction tx = null; 
  try { 
  tx = session.beginTransaction(); 
  Customer customer=(Customer)session.load(Customer.class,new Long(customer_id)); 
  tx.commit(); 
  return customer; 
  }catch (Exception e) { 
  if (tx != null) { 
  // Something went wrong; discard all partial changes 
  tx.rollback(); 
  } 
  throw e; 
  } finally { 
  // No matter what, close the session 
  session.close(); 
  } 
当执行到"session.load"时报错: 
net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of com.Customer.name 
请问哪里的问题?

------解决方案--------------------
xml映射文件内容不对
------解决方案--------------------
检查com.xxxx
是否有public string setName方法

------解决方案--------------------
<class name="Customer" dynamic-insert="true" dynamic-update="true" table="CUSTOMERS">
<id name="id">
<generator class="increment"/>
</id>

<property name="name"/>
<property name="sex" access="field" />

这里映射没有标出id 没有和表里具体字段关联,
name 也没有和表里具体字段关联.
异常说的是Customer类里面没有public void setName(String name)方法,方法名严格区分大小写的