我的表映射文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="entity.Emp" table="EMP" schema="SCOTT">
<id name="empno" type="long">
<column name="EMPNO" precision="4" scale="0" />
<generator class="native" />
</id>
<property name="ename" type="string">
<column name="ENAME" length="10" />
</property>
<property name="job" type="string">
<column name="JOB" length="9" />
</property>
<property name="mgr" type="long">
<column name="MGR" precision="4" scale="0" />
</property>
<property name="hiredate" type="date">
<column name="HIREDATE" length="7" />
</property>
<property name="sal" type="double">
<column name="SAL" precision="7" />
</property>
<!--
<property name="comm" type="double">
<column name="COMM" precision="7" />
</property>
--> </class>
</hibernate-mapping>我的hibernate.cfg.xml:<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">scott</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:myOra
</property>
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="myeclipse.connection.profile">oracle</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping resource="entity/Emp.hbm.xml" /> </session-factory></hibernate-configuration>
我的DAO:package dao;import java.util.List;import org.hibernate.Query;
import org.hibernate.Session;import util.HibernateSessionFactory;import entity.Emp;public class EmpDaoImpl extends BaseDao implements EmpDao{ public List<Emp> selectAll() {
Session session = this.getSession();
System.out.println("session------------"+session);
String hql ="from Emp emp";
Query query = session.createQuery(hql);
System.out.println("query---------------"+query.getQueryString());
List<Emp> list = query.list();
session.close();
return list;
} public Emp selectById(long id) {
Session session = this.getSession();
Emp e = (Emp) session.get(Emp.class, id);
System.out.println("daoimpl------------------"+e);
return e;
}}问题:当进行id查询的时候,如果遇到数据库字段为null的情况时候,那么会报错,如下:org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of entity.Emp.setComm
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="entity.Emp" table="EMP" schema="SCOTT">
<id name="empno" type="long">
<column name="EMPNO" precision="4" scale="0" />
<generator class="native" />
</id>
<property name="ename" type="string">
<column name="ENAME" length="10" />
</property>
<property name="job" type="string">
<column name="JOB" length="9" />
</property>
<property name="mgr" type="long">
<column name="MGR" precision="4" scale="0" />
</property>
<property name="hiredate" type="date">
<column name="HIREDATE" length="7" />
</property>
<property name="sal" type="double">
<column name="SAL" precision="7" />
</property>
<!--
<property name="comm" type="double">
<column name="COMM" precision="7" />
</property>
--> </class>
</hibernate-mapping>我的hibernate.cfg.xml:<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">scott</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:myOra
</property>
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="myeclipse.connection.profile">oracle</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping resource="entity/Emp.hbm.xml" /> </session-factory></hibernate-configuration>
我的DAO:package dao;import java.util.List;import org.hibernate.Query;
import org.hibernate.Session;import util.HibernateSessionFactory;import entity.Emp;public class EmpDaoImpl extends BaseDao implements EmpDao{ public List<Emp> selectAll() {
Session session = this.getSession();
System.out.println("session------------"+session);
String hql ="from Emp emp";
Query query = session.createQuery(hql);
System.out.println("query---------------"+query.getQueryString());
List<Emp> list = query.list();
session.close();
return list;
} public Emp selectById(long id) {
Session session = this.getSession();
Emp e = (Emp) session.get(Emp.class, id);
System.out.println("daoimpl------------------"+e);
return e;
}}问题:当进行id查询的时候,如果遇到数据库字段为null的情况时候,那么会报错,如下:org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of entity.Emp.setComm
解决方案 »
- 关于在jsp页面中调用接口
- windows历史记录功能在java程序中如何实现
- 大家来投个票吧----大家现在最常用的浏览器是什么?
- 前台运行正常 Struts 2 action 问题在 Tomcat 6.0\logs\stdout_20100414.log全是这种错误
- google API 能帮下吗?
- 一个 类型转换的问题
- 听说Style Report出了新版本,有谁知道具体有什么不同吗?
- 80分求weblogic 7.0或8.1的详细配置
- weblogic下struts报错如下
- 请问,weblogic 中,javabean放在什么目录下,jsp放在什么目录下?
- SOS 不知道为什么 突然页面无法显示 报错如下
- EXT在火狐中不好使 为什么啊。。。求围观!
double改为 Double