Hibernate:无法从结果集中读取列值:无法转换为内部表示

时间:2013-09-04 06:31:05

标签: java hibernate

我正在尝试从DB中获取值。我已经成功配置了hibernate。下面是我的hbm文件和pojo类。

<class name="UserMasterBean" table="EMPLOYEE_MASTER">
    <id name="Id" type="long">
        <column name="EMP_ID" length="10" />
        <generator class="assigned" />
    </id>
    <property name="FirstName" type="string">
        <column name="EMP_FIRST_NAME" length="30" not-null="true" />
    </property>
    <property name="SecondName" type="string">
        <column name="EMP_SECOND_NAME" length="30" />
    </property>
    <property name="LastName" type="string">
        <column name="EMP_LAST_NAME" length="30" />
    </property>

    <property name="empDob" type="date">
        <column name="EMP_DOB" length="7" not-null="true" />
    </property>
    <property name="empDoj" type="date">
        <column name="EMP_DOJ" length="7" not-null="true" />
    </property>
    <property name="empPermAdd1" type="string">
        <column name="EMP_PERM_ADD1" length="50" not-null="true" />
    </property>
<!--Other Properties removed-->
下面是我的pojo课程

public class UserMasterBean {

private Long id;
private String loginName;
private String password;
private String type;
private String loginYN;
private String salutation;
private String firstName;
private String secondName;
private String lastName;
private String gender;
private String maritalStatus;
private String pagerNo;
private String phoneNo;
private String mobileNo;
private String emailId;
private String personalMailId;
private Long companyId;
private String companyName;
private Long worldWideRegion;
private Long country;
private Long localRegion;
private Long state;
private Long city;
private Long department;
private String curriculum;
private String dn;
private String photoPath;
private java.sql.Timestamp empDob;
private java.sql.Timestamp empDoj;
private java.sql.Timestamp empDol;
private java.sql.Timestamp empDoc;
private String empPanNo;
private String empBloodGroup;
private String empCurrcBand;
private String empPassportNo;
private String empManager;


public String getFieldPrefix() {
    return fieldPrefix;
}

public Long getId() {
    return id;
}

public String getLoginName() {
    return loginName;
}

public String getPassword() {
    return password;
}

public String getType() {
    return type;
}

public String getLoginYN() {
    return loginYN;
}

public String getSalutation() {
    return salutation;
}

public String getFirstName() {
    return firstName;
}

public String getSecondName() {
    return secondName;
}

public String getLastName() {
    return lastName;
}
/* Amit Gupte - Modified - IUser Begin */

public String getMiddleName() {
    return secondName;
}

public String getName() {
    return firstName + " " + lastName;
}
/* Amit Gupte - Modified - IUser End*/

public String getGender() {
    return gender;
}

public String getMaritalStatus() {
    return maritalStatus;
}

public String getPagerNo() {
    return pagerNo;
}

public String getPhoneNo() {
    return phoneNo;
}

public String getMobileNo() {
    return mobileNo;
}

public String getEmailId() {
    return emailId;
}

public String getPersonalMailId() {
    return personalMailId;
}

public Long getCompanyId() {
    return companyId;
}

public String getCompanyName() {
    return companyName;
}

public Long getWorldWideRegion() {
    return worldWideRegion;
}

public Long getCountry() {
    return country;
}

public Long getLocalRegion() {
    return localRegion;
}

public Long getState() {
    return state;
}

public Long getCity() {
    return city;
}

public Long getDepartment() {
    return department;
}

public String getCurriculum() {
    return curriculum;
}

public String getDn() {
    return dn;
}

public String getPhotoPath() {
    return photoPath;
}

public java.sql.Timestamp getEmpDob() {
    return empDob;
}

public java.sql.Timestamp getEmpDoj() {
    return empDoj;
}

public java.sql.Timestamp getEmpDol() {
    return empDol;
}

public java.sql.Timestamp getEmpDoc() {
    return empDoc;
}

public String getEmpPanNo() {
    return empPanNo;
}

public String getEmpBloodGroup() {
    return empBloodGroup;
}

public String getEmpCurrcBand() {
    return empCurrcBand;
}

public String getEmpPassportNo() {
    return empPassportNo;
}

public String getEmpManager() {
    return empManager;
}



//Other methods removed

}

我面临以下错误。

Sep 04, 2013 11:50:19 AM org.hibernate.type.NullableType nullSafeGet
INFO: could not read column value from result set: EMP1_0_; Fail to convert to internal           representation
Sep 04, 2013 11:50:19 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 17059, SQLState: 99999
Sep 04, 2013 11:50:19 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Fail to convert to internal representation

我的代码没有出错。

我查询

String hql = "from UserMasterBean";
    List empList = attendance.getList(hql, factory);

其他课程的工作

1 个答案:

答案 0 :(得分:5)

当为一个不是数字的字符串表示形式的VARCHAR值调用getInt(或其他一些数字类型)时,抛出此错误。如果VARCHAR列包含'BOB'并且您在该列上调用getInt,则会出现此错误。