Ok, i am able to remove those errors. Just shifted my project from NetBEans 5.5 to Eclipse 3.2 with MyEclipse installed on it and i am able to run the relation free hibernate for Roles and Users.
Now, Roles object is being included in Users. When i earlier tried to load users without role object (using role as int instead of Roles class) it loaded fine. but now when i have made the relation it is giving me this exception.
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of database.beans.Users.role
My Users.hbm.xml file is
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : Roles.xml
Created on : February 22, 2007, 4:26 PM
Author : alim
Description:
Purpose of the document follows.
-->
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="database.beans.Users" table="users">
<id name="id" type="integer">
<column name="Id"/>
<generator class="assigned"/>
</id>
<property name="userName" type="string">
<column name="UserName" />
</property>
<property name="userPassword" type="string">
<column name="UserPassword" />
</property>
<many-to-one name="role" class="database.beans.Roles" fetch="join">
<column name="Role" />
</many-to-one>
</class>
</hibernate-mapping>
and my Java file for Users is
Code:
/*
* Users.java
*
* Created on February 16, 2007, 1:12 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package database.beans;
/**
*
* @author alim
*/
public class Users {
private int id;
private String userName;
private String userPassword;
private String email;
private Roles role;
public Users() {
id = 0;
userName = new String("");
userPassword = new String("");
email = new String("");
// role = 0;
role = new Roles();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getRole() {
return role.getId();
}
public void setRole(int role) {
if (this.role == null) {
this.role = new Roles();
}
this.role.setId(role);
}
public void setRole (Roles role){
this.role = role;
}
}
I hope this will be solved.