I have two java classes:
Code:
public class User implements Serializable{
private int id;
private String username;
private String password;
protected User(){
}
public User(String username, String password){
this.setUsername(username);
this.setPassword(password);
}
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 getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
and:
Code:
public class Teacher implements Serializable{
//private int id;
private String degree;
private String firstName;
private String secondName;
private String familyName;
private String email;
protected Teacher(){
}
public Teacher(String degree, String firstName,
String secondName, String familyName, String email){
this.setDegree(degree);
this.setFirstName(firstName);
this.setSecondName(secondName);
this.setFamilyName(familyName);
this.setEmail(email);
}
//public int getId() {
// return id;
//}
//public void setId(int id) {
// this.id = id;
//}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSecondName() {
return secondName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public String getFamilyName() {
return familyName;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
My mapping files look like this:
Code:
<hibernate-mapping>
<class name="pl.umk.mat.redKite.security.data.User" table="users">
<id name="id" column="userId">
<generator class="increment"/>
</id>
<property name="username" type="string" length="20"
column="username" not-null="true"/>
<property name="password" type="string" length="20"
column="password" not-null="true"/>
<set name="userRoles" table="joinUsersAndUsersRoles">
<key column="userId"/>
<many-to-many column="userRoleId"
class="pl.umk.mat.redKite.security.data.UserRole"/>
</set>
</class>
</hibernate-mapping>
and:
Code:
<hibernate-mapping>
<union-subclass
name="pl.umk.mat.redKite.main.teacher.data.Teacher"
extends="pl.umk.mat.redKite.security.data.User"
table="teachers">
<property name="degree" type="string" length="10"
column="degree"/>
<property name="firstName" type="string" length="20"
column="firstName" not-null="true"/>
<property name="secondName" type="string" length="20"
column="secondName"/>
<property name="familyName" type="string" length="50"
column="familyName" not-null="true"/>
<property name="email" type="string" length="50"
column="email"/>
<set name="subjects" inverse="true">
<key column="teacherId"/>
<one-to-many class="pl.umk.mat.redKite.main.teacher.data.TeachersForSubjects"/>
</set>
<set name="classes" inverse="true">
<key column="wychId"/>
<one-to-many class="pl.umk.mat.redKite.main.classes.data.Classes"/>
</set>
</union-subclass>
</hibernate-mapping>
and I have a problem when I run program, I have a error:
Code:
2008-01-11 00:46:10,312 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: pl.umk.mat.redKite.security.data.User, getter method of property: id>
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of pl.umk.mat.redKite.security.data.User.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:64)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at hibernateTemp.TworzenieBazy.main(TworzenieBazy.java:39)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 9 more
What I do wrong??