-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: org.hibernate.PropertyAccessException:IllegalArgumentExcepti
PostPosted: Thu Feb 09, 2006 3:53 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
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.



_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:13 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Could it be because of the 'type="java.lang.String"' attribute? The ref docs say to use hibernate types, not the java types, so 'type="string"' is correct. However I've seen people post mappings using 'type="java.lang.Integer"' and it seems to work for them. I've only ever used the type="string"/type="integer" way of doing things, so this is just a guess...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:18 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Quote:
Code:
HibernateTemplate template = getHibernateTemplate();
Class clazz = OrgRoleTyp.class;
ClassMetadata classMetadata = template.getSessionFactory().getClassMetadata(clazz);
classMetadata.setPropertyValue(clazz,"orgRoleTypNm","APradesh",EntityMode.POJO);
template.save(clazz);


what are you trying to do here ?
looks like you trying to set a property on java.lang.Class object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:38 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
I am trying to set the orgRoleTypNm property of OrgRoleTyp Object , which is a Pojo object.

_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:41 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
where is the instance of this pojo ? cannot see it in the code.
Why can't you just call the setter method on the pojo instance?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:47 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
Yes, you are correct, but I am trying this code not specific to one pojo object. Later I would set - Class clazz = OrgRoleTyp.class; dynamically, so that this code works for any pojo Object.

_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:51 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Yes but hibernate needs the pojo instance not the class object.

classMetadata.setPropertyValue(clazz,"orgRoleTypNm","APradesh",EntityMode.POJO);

This method expects the first parameter to be an instance of a mapped entity not a class object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:21 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
I think you are correct, I need to find a way to dynamically get a pojo object and pass it to classMetadata.setPropertyValue method.

Thanks

_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:26 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
please rate also if a post helped.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:44 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
Sure, I was just about to do it... :) Thanks for correcting my mistake.

I will come back again after I get any solution, in mean while if some one can suggest me that would be of great help.

Thx

_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:54 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Try something like this:
Code:
typ = new OrgRoleType();
typ.setOrgRoleTypNm("APradesh");
template.save(typ);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 7:33 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
Yes, Finallly I am able to insert successfully and if I pass OrgRoleTyp.class dynamically, I would make the following code working for any pojo object. :)

HibernateTemplate template = getHibernateTemplate();
Class clazz = OrgRoleTyp.class;
Object obj = clazz.newInstance();
ClassMetadata classMetadata = template.getSessionFactory().getClassMetadata(clazz);
classMetadata.setPropertyValue(obj,"orgRoleTypNm","APradesh",EntityMode.POJO);
template.save(obj);

Thank you all

_________________
Deva


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 7:37 pm 
Newbie

Joined: Thu Jan 19, 2006 12:42 pm
Posts: 7
Location: Des Moines
Some corrections to the my previous post :D

Yes, Finallly I am able to insert successfully and if I pass OrgRoleTyp.class,orgRoleTypNm and APradesh dynamically, I would make the following code working for any pojo object. :)

HibernateTemplate template = getHibernateTemplate();
Class clazz = OrgRoleTyp.class;
Object obj = clazz.newInstance();
ClassMetadata classMetadata = template.getSessionFactory().getClassMetadata(clazz);
classMetadata.setPropertyValue(obj,"orgRoleTypNm","APradesh",EntityMode.POJO);
template.save(obj);

Thank you all

_________________
Deva


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.