-->
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.  [ 3 posts ] 
Author Message
 Post subject: IllegalArgumentException occurred calling getter method
PostPosted: Fri Jan 19, 2007 5:24 pm 
Beginner
Beginner

Joined: Wed Oct 25, 2006 12:10 pm
Posts: 41
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.2

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>
<class name="test.DeviceType" table="DEVICE_TYPE">
<id name="id" column="ID" unsaved-value="0" >
<generator class="increment"/>
</id>

<property name="deviceType">
<column name="NAME" />
</property>

<property name="description">
<column name="DESC" />
</property>

<set name="roles" table="DEVICETYPE_ROLES" inverse="true" cascade="all">
<key column="DEVICETYPE_ID" />
<many-to-many column="ROLE_ID" class="test.Role"/>
</set>

</class>

<class name="test.Role" table="ROLE">
<id name="id" column="ID">
<generator class="assigned">
</generator>
</id>

<property name="name" column="NAME" />

</class>



</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
package test;

import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.dao.DataAccessException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.dao.DataAccessException;
import org.hibernate.HibernateException;



public class DeviceDao {

private HibernateTemplate hibernateTemplate;
protected final Log logger = LogFactory.getLog(getClass());

public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
logger.info(" *** In setHibernateTemplate method *** ");
this.hibernateTemplate = hibernateTemplate;
}
public void persist(DeviceType dt) {
logger.info(" *** In persist method *** ");
System.out.println(" *** In persist method *** ");
// System.out.println("***ID="+dt.getId()+"***DeviceType="+dt.getDeviceType()+"***Desc="+dt.getDescription());
// hibernateTemplate.save(dt);
System.out.println("***ID="+dt.getId()+"***DeviceType="+dt.getDeviceType()+"***Desc="+dt.getDescription()+"***Role Size="+dt.getRoles().size());
hibernateTemplate.save(dt);
System.out.println("ID***="+dt.getId());
}
public void update(DeviceType instance) {
hibernateTemplate.update(instance);
}
public void remove(Long deviceTypeId) {
Object device = hibernateTemplate.load(DeviceType.class, deviceTypeId);
hibernateTemplate.delete(device);
}



public List getDeviceTypes() throws DataAccessException {

return (List) hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
String sql = "select dt.id, dt.deviceType from DeviceType dt";
Query query = session.createQuery(sql);
return query.list();
}
});

}

public DeviceType getDeviceType(Long id) {
System.out.println("***In DeviceDao selectedDevice***"+id);
DeviceType dt = (DeviceType) hibernateTemplate.get(DeviceType.class, id);
if (dt == null) {
throw new ObjectRetrievalFailureException(DeviceType.class, id);
}
return dt;
}

}




Full stack trace of any exception that occurs:
2007-01-19 12:14:03,759 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: test.Role, getter method of property: id>
2007-01-19 12:14:03,759 WARN [test.TestBean] - <IllegalArgumentException occurred calling getter of test.Role.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Role.id>



Name and version of the database you are using:
HSQLDB


The generated SQL (show_sql=true):
Expected to generate following SQL statements but it doesn't due to Error
insert into DeviceType_Roles(DeviceType_id, Tole_Id) values (?, ?)
insert into Device_Type(Id, Name, Desc) values(?,?,?)



Debug level Hibernate log excerpt:
2007-01-19 12:14:03,759 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: test.Role, getter method of property: id>
2007-01-19 12:14:03,759 WARN [test.TestBean] - <IllegalArgumentException occurred calling getter of test.Role.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Role.id>





Problems with Session and transaction handling?
Nope

Scenario :
Its an example of Many-To-Many Object Relationship i.e. DeviceType object is associated with Roles object. Here is the snippet
DeviceType dt = new DeviceType();
dt.setDeviceType(deviceType);
dt.setDescription(description);
dt.setRoles(deviceRoles);
deviceDao.persist(dt); // In Business Layer
Please not deviceRoles is Set of Roles.
deviceDao.persist(dt); results in call to Hibernate Layer and executes hibernateTemplate.save(dt);

Expected Results:
To persist DeviceType object along with set of Roles into DeviceType table and DeviceType_Roles table as shown below
insert into DeviceType_Roles(DeviceType_id, Tole_Id) values (?, ?)
insert into Device_Type(Id, Name, Desc) values(?,?,?)

Observed Results:
IllegalArgumentException occurred calling getter method of property: id>

Any pointers/suggestions will be highly appreciated

Regards
Bansi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 10:14 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Can you show the Role class? Did you try to debug the getId method in Role class?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 12:21 am 
Beginner
Beginner

Joined: Wed Oct 25, 2006 12:10 pm
Posts: 41
Hi Somu
Thanks for response
Here are the POJOs and the mapping file

DeviceType.java
[code]
package test;
import java.util.Set;
public class DeviceType {
private Long id;
private String deviceType;
private String description;
private Set roles;

public DeviceType(){

}

public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

public Set getRoles() {
return roles;
}

public void setRoles(Set roles) {
this.roles = roles;
}


}

[/code]

Role.java
[code]

package test;

public class Role {
private Long id;
private String name;

public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}

[/code]

Mapping File : deviceType.hbm.xml
[code]
<?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="test.DeviceType" table="DEVICE_TYPE">
<id name="id" column="ID" unsaved-value="0" >
<generator class="increment"/>
</id>

<property name="deviceType">
<column name="NAME" />
</property>

<property name="description">
<column name="DESC" />
</property>

<set name="roles" table="DEVICETYPE_ROLES" inverse="true" cascade="all">
<key column="DEVICETYPE_ID" />
<many-to-many column="ROLE_ID" class="test.Role"/>
</set>

</class>

<class name="test.Role" table="ROLE">
<id name="id" column="ID">
<generator class="assigned">
</generator>
</id>

<property name="name" column="NAME" />

</class>
</hibernate-mapping>
[/code]

Here is the full stack trace
Code:

2007-01-19 12:14:03,759 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: test.Role, getter method of property: id>
2007-01-19 12:14:03,759 WARN [test.TestBean] - <IllegalArgumentException occurred calling getter of test.Role.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Role.id>

Quote:
The Role has its ID values stored in the Database hence using "assigned" as the ID generator however in case of DeviceType whenever user submits the JSF form a new ID with an increment of 1 has to be inserted in the Database along with other field values

Any pointers/suggestions will be highly appreciated


Regards
Bansi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.