期望类型:java.lang.Integer,实际值:java.lang.Integer

时间:2013-06-11 05:17:11

标签: java hibernate java-ee jboss

我想做什么? 在加载我的项目时,我得到一个奇怪的例外:

  

rezg.admin.server.objects.common.pojo.EmailLogDetails,属性的setter方法:id

我是使用postgres将对象(持久化)保存到数据库中。环境是Java 6,Jboss 4环境中的Hibernate 3。 jar包含“EmailLogDetails”在Jboss lib文件夹中。

  

期望类型:java.lang.Integer,实际值:java.lang.Integer类中的IllegalArgumentException:   rezg.admin.server.objects.common.pojo.EmailLogDetails,setter方法   属性:id

     

org.hibernate.PropertyAccessException:IllegalArgumentException   调用setter时发生的   rezg.admin.server.objects.common.pojo.EmailLogDetails.Id at   org.hibernate.property.BasicPropertyAccessor $ BasicSetter.set(BasicPropertyAccessor.java:104)     在   org.hibernate.tuple.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:204)     在   org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:3261)     在   org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:157)     在   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114).....

     

引起:java.lang.IllegalArgumentException:object不是声明类的实例   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:601)at   org.hibernate.property.BasicPropertyAccessor $ BasicSetter.set(BasicPropertyAccessor.java:42)     ... 74更多

EmailLogDetails:

public class EmailLogDetails  implements java.io.Serializable {

private static final long serialVersionUID = 1L;
private java.lang.Integer id;
private String reservationNo;
private String mailSubject;
private String fromAddress;

public String getFromAddress() {
    return fromAddress;
}
public void setFromAddress(String fromAddress) {
    this.fromAddress = fromAddress;
}
public java.lang.Integer getId() {
    return id;
}
public void setId(java.lang.Integer id) {
    this.id = id;
}
public String getMailSubject() {
    return mailSubject;
}
public void setMailSubject(String mailSubject) {
    this.mailSubject = mailSubject;
}
public String getMailType() {
    return mailType;
}
}

XML

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "../server/default/conf/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false" schema="@@portalname@@_admin">
<class   name="rezg.admin.server.objects.common.pojo.EmailLogDetails" table="emaillogdetails">

      <id name="Id" column="id" type="java.lang.Integer">
        <generator class="sequence">
          <param name="sequence">@@portalname@@_admin.seq_emaillogdetails</param>
        </generator>
    </id>

    <property name="reservationNo"  type="java.lang.String" >
        <column name="reservationno" length="20" not-null="false" sql-type="varchar" />
    </property>

    <property name="mailSubject"  type="java.lang.String" >
        <column name="mailsubject" length="500" not-null="false" sql-type="varchar" />
    </property>

1 个答案:

答案 0 :(得分:0)

从它的外观来看,你缺少默认的构造函数。在播放DB和类之间的映射信息的导入和导出之前,Hibernate会查找默认构造函数来创建实例。