这是我的休眠POJO类。

StockModel.java

import java.util.Date;

public class StockModel implements java.io.Serializable{

    private static final long serialVersionUID = 1L;
    private String s_model_id;
    private String s_prod_id;
    private String s_model_name;
    private String s_model_type;
    private char c_epos_type;
    private String s_model_ver;
    private String s_model_cat;
    private String s_oem;
    private char c_voice_facility;
    private char c_actual_distance;
    private char c_sim_lock;
    private char c_emergency;
    private char c_accdacc;
    private char c_ignition;
    private char c_battery;
    private char c_tampering;
    private char c_overspeed;
    private char c_fuelknob;
    private char c_routedeviation;
    private char c_swipedetection;
    private char c_circular_geofence;
    private char c_polygonal_geofence;
    private char c_gps_antennae;
    private char c_gsm_antennae;
    private char c_adc;
    private char c_accident_data;

    private char c_is_active = 'Y';
    private String s_created_by;
    private Date dt_created;
    private String s_modified_by;
    private Date dt_modified;
    private char c_is_deleted = 'N';

    /**
     * @return the s_model_id
     */
    public String getS_model_id() {
        return s_model_id;
    }
    /**
     * @param s_model_id the s_model_id to set
     */
    public void setS_model_id(String s_model_id) {
        this.s_model_id = s_model_id;
    }
    /**
     * @return the s_prod_id
     */
    public String getS_prod_id() {
        return s_prod_id;
    }
    /**
     * @param s_prod_id the s_prod_id to set
     */
    public void setS_prod_id(String s_prod_id) {
        this.s_prod_id = s_prod_id;
    }
    /**
     * @return the s_model_name
     */
    public String getS_model_name() {
        return s_model_name;
    }
    /**
     * @param s_model_name the s_model_name to set
     */
    public void setS_model_name(String s_model_name) {
        this.s_model_name = s_model_name;
    }
    /**
     * @return the s_model_type
     */
    public String getS_model_type() {
        return s_model_type;
    }
    /**
     * @param s_model_type the s_model_type to set
     */
    public void setS_model_type(String s_model_type) {
        this.s_model_type = s_model_type;
    }
    /**
     * @return the c_epos_type
     */
    public char getC_epos_type() {
        return c_epos_type;
    }
    /**
     * @param c_epos_type the c_epos_type to set
     */
    public void setC_epos_type(char c_epos_type) {
        this.c_epos_type = c_epos_type;
    }
    /**
     * @return the s_model_ver
     */
    public String getS_model_ver() {
        return s_model_ver;
    }
    /**
     * @param s_model_ver the s_model_ver to set
     */
    public void setS_model_ver(String s_model_ver) {
        this.s_model_ver = s_model_ver;
    }
    /**
     * @return the s_model_cat
     */
    public String getS_model_cat() {
        return s_model_cat;
    }
    /**
     * @param s_model_cat the s_model_cat to set
     */
    public void setS_model_cat(String s_model_cat) {
        this.s_model_cat = s_model_cat;
    }
    /**
     * @return the s_oem
     */
    public String getS_oem() {
        return s_oem;
    }
    /**
     * @param s_oem the s_oem to set
     */
    public void setS_oem(String s_oem) {
        this.s_oem = s_oem;
    }
    /**
     * @return the c_voice_facility
     */
    public char getC_voice_facility() {
        return c_voice_facility;
    }
    /**
     * @param c_voice_facility the c_voice_facility to set
     */
    public void setC_voice_facility(char c_voice_facility) {
        this.c_voice_facility = c_voice_facility;
    }
    /**
     * @return the c_actual_distance
     */
    public char getC_actual_distance() {
        return c_actual_distance;
    }
    /**
     * @param c_actual_distance the c_actual_distance to set
     */
    public void setC_actual_distance(char c_actual_distance) {
        this.c_actual_distance = c_actual_distance;
    }
    /**
     * @return the c_sim_lock
     */
    public char getC_sim_lock() {
        return c_sim_lock;
    }
    /**
     * @param c_sim_lock the c_sim_lock to set
     */
    public void setC_sim_lock(char c_sim_lock) {
        this.c_sim_lock = c_sim_lock;
    }
    /**
     * @return the c_emergency
     */
    public char getC_emergency() {
        return c_emergency;
    }
    /**
     * @param c_emergency the c_emergency to set
     */
    public void setC_emergency(char c_emergency) {
        this.c_emergency = c_emergency;
    }
    /**
     * @return the c_accdacc
     */
    public char getC_accdacc() {
        return c_accdacc;
    }
    /**
     * @param c_accdacc the c_accdacc to set
     */
    public void setC_accdacc(char c_accdacc) {
        this.c_accdacc = c_accdacc;
    }
    /**
     * @return the c_ignition
     */
    public char getC_ignition() {
        return c_ignition;
    }
    /**
     * @param c_ignition the c_ignition to set
     */
    public void setC_ignition(char c_ignition) {
        this.c_ignition = c_ignition;
    }
    /**
     * @return the c_battery
     */
    public char getC_battery() {
        return c_battery;
    }
    /**
     * @param c_battery the c_battery to set
     */
    public void setC_battery(char c_battery) {
        this.c_battery = c_battery;
    }
    /**
     * @return the c_tampering
     */
    public char getC_tampering() {
        return c_tampering;
    }
    /**
     * @param c_tampering the c_tampering to set
     */
    public void setC_tampering(char c_tampering) {
        this.c_tampering = c_tampering;
    }
    /**
     * @return the c_overspeed
     */
    public char getC_overspeed() {
        return c_overspeed;
    }
    /**
     * @param c_overspeed the c_overspeed to set
     */
    public void setC_overspeed(char c_overspeed) {
        this.c_overspeed = c_overspeed;
    }
    /**
     * @return the c_fuelknob
     */
    public char getC_fuelknob() {
        return c_fuelknob;
    }
    /**
     * @param c_fuelknob the c_fuelknob to set
     */
    public void setC_fuelknob(char c_fuelknob) {
        this.c_fuelknob = c_fuelknob;
    }
    /**
     * @return the c_routedeviation
     */
    public char getC_routedeviation() {
        return c_routedeviation;
    }
    /**
     * @param c_routedeviation the c_routedeviation to set
     */
    public void setC_routedeviation(char c_routedeviation) {
        this.c_routedeviation = c_routedeviation;
    }
    /**
     * @return the c_swipedetection
     */
    public char getC_swipedetection() {
        return c_swipedetection;
    }
    /**
     * @param c_swipedetection the c_swipedetection to set
     */
    public void setC_swipedetection(char c_swipedetection) {
        this.c_swipedetection = c_swipedetection;
    }
    /**
     * @return the c_is_active
     */
    public char getC_is_active() {
        return c_is_active;
    }
    /**
     * @param c_is_active the c_is_active to set
     */
    public void setC_is_active(char c_is_active) {
        this.c_is_active = c_is_active;
    }
    /**
     * @return the s_created_by
     */
    public String getS_created_by() {
        return s_created_by;
    }
    /**
     * @param s_created_by the s_created_by to set
     */
    public void setS_created_by(String s_created_by) {
        this.s_created_by = s_created_by;
    }
    /**
     * @return the dt_created
     */
    public Date getDt_created() {
        return dt_created;
    }
    /**
     * @param dt_created the dt_created to set
     */
    public void setDt_created(Date dt_created) {
        this.dt_created = dt_created;
    }
    /**
     * @return the s_modified_by
     */
    public String getS_modified_by() {
        return s_modified_by;
    }
    /**
     * @param s_modified_by the s_modified_by to set
     */
    public void setS_modified_by(String s_modified_by) {
        this.s_modified_by = s_modified_by;
    }
    /**
     * @return the dt_modified
     */
    public Date getDt_modified() {
        return dt_modified;
    }
    /**
     * @param dt_modified the dt_modified to set
     */
    public void setDt_modified(Date dt_modified) {
        this.dt_modified = dt_modified;
    }
    /**
     * @return the c_is_deleted
     */
    public char getC_is_deleted() {
        return c_is_deleted;
    }
    /**
     * @param c_is_deleted the c_is_deleted to set
     */
    public void setC_is_deleted(char c_is_deleted) {
        this.c_is_deleted = c_is_deleted;
    }
    /**
     * @return the c_circular_geofence
     */
    public char getC_circular_geofence() {
        return c_circular_geofence;
    }
    /**
     * @param c_circular_geofence the c_circular_geofence to set
     */
    public void setC_circular_geofence(char c_circular_geofence) {
        this.c_circular_geofence = c_circular_geofence;
    }
    /**
     * @return the c_polygonal_geofence
     */
    public char getC_polygonal_geofence() {
        return c_polygonal_geofence;
    }
    /**
     * @param c_polygonal_geofence the c_polygonal_geofence to set
     */
    public void setC_polygonal_geofence(char c_polygonal_geofence) {
        this.c_polygonal_geofence = c_polygonal_geofence;
    }
    /**
     * @return the c_gps_antennae
     */
    public char getC_gps_antennae() {
        return c_gps_antennae;
    }
    /**
     * @param c_gps_antennae the c_gps_antennae to set
     */
    public void setC_gps_antennae(char c_gps_antennae) {
        this.c_gps_antennae = c_gps_antennae;
    }
    /**
     * @return the c_gsm_antennae
     */
    public char getC_gsm_antennae() {
        return c_gsm_antennae;
    }
    /**
     * @param c_gsm_antennae the c_gsm_antennae to set
     */
    public void setC_gsm_antennae(char c_gsm_antennae) {
        this.c_gsm_antennae = c_gsm_antennae;
    }
    /**
     * @return the c_adc
     */
    public char getC_adc() {
        return c_adc;
    }
    /**
     * @param c_adc the c_adc to set
     */
    public void setC_adc(char c_adc) {
        this.c_adc = c_adc;
    }
    /**
     * @return the c_accident_data
     */
    public char getC_accident_data() {
        return c_accident_data;
    }
    /**
     * @param c_accident_data the c_accident_data to set
     */
    public void setC_accident_data(char c_accident_data) {
        this.c_accident_data = c_accident_data;
    }

}


这是我的StockModel.hbm.xml文件的代码。

<?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>
        <class name="com.projectv4.rtt.Hibernate.valueObjects.StockModel" table="syn_model">

            <id name="s_model_id"  column="S_MODEL_ID">
                <generator class="assigned"></generator>
            </id>

            <property name="s_prod_id" >
                <column name="S_PROD_ID"></column>
            </property>
            <property name="s_model_name"  not-null="true">
                <column name="S_MODEL_NAME"></column>
            </property>
            <!-- <property name="s_model_type" >
                <column name="S_MODEL_TYPE"></column>
            </property> -->
            <property name="c_epos_type"  length="1">
                <column name="C_EPOS_TYPE" length="1"></column>
            </property>
            <property name="s_model_ver" >
                <column name="S_MODEL_VER"></column>
            </property>
            <property name="s_model_cat" >
                <column name="S_MODEL_CAT"></column>
            </property>
            <property name="s_oem" >
                <column name="S_OEM"></column>
            </property>
            <property name="c_voice_facility" type="char" length="1">
                <column name="C_VOICE_FACILITY" length="1" default="N"></column>
            </property>
            <property name="c_actual_distance" type="char" length="1">
                <column name="C_ACTUAL_DISTANCE" length="1" default="N"></column>
            </property>
            <property name="c_sim_lock" type="char" length="1">
                <column name="C_SIM_LOCK" length="1" default="N"></column>
            </property>
            <property name="c_emergency" type="char" length="1">
                <column name="C_EMERGENCY" length="1" default="N"></column>
            </property>
            <property name="c_accdacc" type="char" length="1">
                <column name="C_ACCDACC" length="1" default="N"></column>
            </property>
            <property name="c_ignition" type="char" length="1">
                <column name="C_IGNITION" length="1" default="N"></column>
            </property>
            <property name="c_battery" type="char" length="1">
                <column name="C_BATTERY" length="1" default="N"></column>
            </property>
            <property name="c_tampering" type="char" length="1">
                <column name="C_TAMPERING" length="1" default="N"></column>
            </property>
            <property name="c_overspeed" type="char" length="1">
                <column name="C_OVERSPEED" length="1" default="N"></column>
            </property>
            <property name="c_fuelknob" type="char" length="1">
                <column name="C_FUELKNOB" length="1" default="N"></column>
            </property>
            <property name="c_routedeviation" type="char" length="1">
                <column name="C_ROUTEDEVIATION" length="1" default="N"></column>
            </property>
            <property name="c_swipedetection" type="char" length="1">
                <column name="C_SWIPEDETECTION" length="1" default="N"></column>
            </property>
            <property name="c_circular_geofence" type="char" length="1">
                <column name="C_CIRCULAR_GEOFENCE" length="1" default="N"></column>
            </property>
            <property name="c_polygonal_geofence" type="char" length="1">
                <column name="C_POLYGONAL_GEOFENCE" length="1" default="N"></column>
            </property>
            <property name="c_gps_antennae" type="char" length="1">
                <column name="C_GPS_ANTENNAE" length="1"></column>
            </property>
            <property name="c_gsm_antennae" type="char" length="1">
                <column name="C_GSM_ANTENNAE" length="1"></column>
            </property>
            <property name="c_adc" type="char" length="1">
                <column name="C_ADC" length="1" default="N"></column>
            </property>
            <property name="c_accident_data" type="char" length="1">
                <column name="C_ACCIDENT_DATA" length="1" default="N"></column>
            </property>
            <property name="c_is_active" type="char" length="1">
                <column name="C_IS_ACTIVE" length="1" default="Y"></column>
            </property>
            <property name="s_created_by" >
                <column name="S_CREATED_BY"></column>
            </property>
            <property name="dt_created" type="timestamp">
                <column name="DT_CREATED" sql-type="datetime" default="SYSDATE"></column>
            </property>
            <property name="s_modified_by" >
                <column name="S_MODIFIED_BY"></column>
            </property>
            <property name="dt_modified" type="timestamp">
                <column name="DT_MODIFIED" sql-type="datetime"></column>
            </property>
            <property name="c_is_deleted" type="char">
                <column name="C_IS_DELETED"></column>
            </property>

        </class>
    </hibernate-mapping>


表SYN_MODEL映射到v4stock.tbl_model

The Database structure can be defined as below -

 Table "v4stock.tbl_model"
        Column        |            Type             |            Modifiers
----------------------+-----------------------------+----------------------------------
 s_model_id           | character varying(20)       | not null
 s_prod_id            | character varying(3)        |
 s_model_name         | character varying(60)       | not null
 s_model_type         | character varying(5)        |
 c_epos_type          | character(1)                |
 s_model_ver          | character varying(50)       |
 s_model_cat          | character varying(50)       |
 s_oem                | character varying(50)       |
 c_voice_facility     | character(1)                | default 'N'::bpchar
 c_actual_distance    | character(1)                | default 'N'::bpchar
 c_sim_lock           | character(1)                | default 'N'::bpchar
 c_emergency          | character(1)                | default 'N'::bpchar
 c_accdacc            | character(1)                | default 'N'::bpchar
 c_ignition           | character(1)                | default 'N'::bpchar
 c_battery            | character(1)                | default 'N'::bpchar
 c_tampering          | character(1)                | default 'N'::bpchar
 c_overspeed          | character(1)                | default 'N'::bpchar
 c_fuelknob           | character(1)                | default 'N'::bpchar
 c_routedeviation     | character(1)                | default 'N'::bpchar
 c_swipedetection     | character(1)                | default 'N'::bpchar
 c_flag_1             | character(1)                | default 'N'::bpchar
 c_flag_2             | character(1)                | default 'N'::bpchar
 c_flag_3             | character(1)                | default 'N'::bpchar
 c_flag_4             | character(1)                | default 'N'::bpchar
 c_flag_5             | character(1)                | default 'N'::bpchar
 c_is_active          | character(1)                | default 'Y'::bpchar
 s_created_by         | character varying(60)       | default 'SYS'::character varying
 dt_created           | timestamp without time zone | default sysdate
 s_modified_by        | character varying(60)       |
 dt_modified          | timestamp without time zone |
 c_is_deleted         | character(1)                | default 'N'::bpchar
 c_circular_geofence  | character(1)                | default 'N'::bpchar
 c_polygonal_geofence | character(1)                | default 'N'::bpchar
 c_gps_antennae       | character(1)                |
 c_gsm_antennae       | character(1)                |
 c_adc                | character(1)                | default 'N'::bpchar
 c_accident_data      | character(1)                | default 'N'::bpchar
Indexes:
    "pk_model" PRIMARY KEY, btree (s_model_id)
    "uk_model" UNIQUE CONSTRAINT, btree (s_model_name)
    "idx_tbl_model_model_id" btree (s_model_id)
Check constraints:
    "chk_gps_antennae" CHECK (c_gps_antennae = ANY (ARRAY['I'::bpchar, 'E'::bpchar]))
    "chk_gsm_antennae" CHECK (c_gsm_antennae = ANY (ARRAY['I'::bpchar, 'E'::bpchar]))
    "chk_model_epos_type" CHECK (c_epos_type = ANY (ARRAY['E'::bpchar, 'G'::bpchar, 'N'::bpchar]))
Foreign-key constraints:
    "fk_model" FOREIGN KEY (s_prod_id) REFERENCES v4stock.tbl_product_mst(s_prod_id) MATCH FULL
Referenced by:
    TABLE "v4alert.tbl_event_alert" CONSTRAINT "fk_alert_model" FOREIGN KEY (s_model_id) REFERENCES v4stock.tbl_model(s_model_id) MATCH FULL
    TABLE "v4stock.tbl_lab_stock" CONSTRAINT "fk_v4_lab_stock" FOREIGN KEY (s_model_id) REFERENCES v4stock.tbl_model(s_model_id) MATCH FULL


当进行休眠调用以访问StockModel时,出现以下异常。

ERROR [STDERR] (http-127.0.0.1-8080-8) org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.projectv4.rtt.Hibernate.valueObjects.StockModel.setC_gps_antennae
    at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215)
    at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185)
    at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2145)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
    at org.hibernate.loader.Loader.list(Loader.java:2024)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
    at com.projectv4.rtt.struts.stock.dao.ModelDataDAO.GetModelData(ModelDataDAO.java:87)
    at com.projectv4.rtt.struts.stock.dao.ModelDataProcess.ProcessGetStockModel(ModelDataProcess.java:121)
    at com.projectv4.rtt.struts.stock.action.ModelActions.execute(ModelActions.java:71)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.internalProcess(ActiveRequestResponseCacheValve.java:74)
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:47)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:599)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)
    at java.lang.Thread.run(Thread.java:679)
Caused by: net.sf.cglib.beans.BulkBeanException
    at com.projectv4.rtt.Hibernate.valueObjects.StockModel$$BulkBeanByCGLIB$$2bd06510.setPropertyValues(<generated>)
    at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
    ... 46 more
Caused by: java.lang.NullPointerException
    ... 48 more


谁能帮我哪里错了?

我已经检查了PropertyAccessException的可能原因,例如安全检查失败,在getter或setter方法内部发生异常,可为空的数据库列映射到原始类型属性,Hibernate类型无法转换为属性类型(或反之亦然),但仍然无法找出此错误的确切原因。

最佳答案

该错误的主要原因是由于数据库中原始类型数据类型c_gps_antennae(属于char类型)与Null值的映射所致。由于基元不能为null,因此无法将其映射到可为空的列。

在数据库中查询c_gps_antennae将返回以下信息。

 select c_gps_antennae from v4stock.tbl_model;
 c_gps_antennae
----------------






(6 rows)


而StockModel.hbm.xml如下所示...

<property name="c_gps_antennae" type="char" length="1">
   <column name="C_GPS_ANTENNAE" length="1"></column>
</property>

09-25 20:40