Hi all, I am trying to insert a record into database table using Hibernate and I get the following exception, when I tested it using JUnit.
(BasicPropertyAccessor.java:66): - expected type: java.lang.String, actual value: java.lang.String
Hibernate version: 3.0.5
database: Oracle9i Enterprise Edition Release 9.2.0.1.0
JDK 1.4.2.08
websphere 5.1.2
Exception :
ERROR [28/09/06 11:28:29:690 CST] org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:62): - IllegalArgumentException in class: com.xxx.model.hibernate.OrgRoleTyp, setter method of property: orgRoleTypNm
ERROR [28/09/06 11:28:29:690 CST] org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66): -
expected type: java.lang.String, actual value: java.lang.String
ERROR [28/09/06 11:28:29:690 CST] com.xxx.model.dao.InTablesTest.testUpdateRecord(InTablesTest.java:38): - org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xxx.model.hibernate.OrgRoleTyp.orgRoleTypNm
INFO [28/09/06 11:28:29:721 CST] org.springframework.test.AbstractTransactionalSpringContextTests.endTransaction(AbstractTransactionalSpringContextTests.java:206): - Rolled back transaction after test execution
---------------------------------------------------------------------------
Mapping documents:
<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.xxx.model.hibernate.OrgRoleTyp"
table="ORG_ROLE_TYP"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true"
batch-size="500"
>
<property
name="orgRoleTypNm"
type="java.lang.String"
column="ORG_ROLE_TYP_NM"
not-null="true"
unique="true"
length="60"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">
@hibernate.property
column="ORG_ROLE_TYP_NM"
unique="true"
length="60"
not-null="true"
</meta>
</property>
</class>
</hibernate-mapping>
---------------------------------------------------------------------------
POJO Object
public class OrgRoleTyp implements java.io.Serializable {
/**
* @hibernate.property
* column="ORG_ROLE_TYP_NM"
* unique="true"
* length="60"
* not-null="true"
*
*/
private String orgRoleTypNm;
/**
* * @hibernate.property
* column="ORG_ROLE_TYP_NM"
* unique="true"
* length="60"
* not-null="true"
*
*/
public String getOrgRoleTypNm() {
return this.orgRoleTypNm;
}
public void setOrgRoleTypNm(String orgRoleTypNm) {
this.orgRoleTypNm = orgRoleTypNm;
}
}
---------------------------------------------------------------------------
Code:
HibernateTemplate template = getHibernateTemplate();
Class clazz = OrgRoleTyp.class;
ClassMetadata classMetadata = template.getSessionFactory().getClassMetadata(clazz);
classMetadata.setPropertyValue(clazz,"orgRoleTypNm","APradesh",EntityMode.POJO);
template.save(clazz);
Could some one please let me know what is the cause for this exception.
Thanks in adv.