-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with union-subclass
PostPosted: Thu Jan 10, 2008 7:59 pm 
Newbie

Joined: Thu Jan 10, 2008 7:48 pm
Posts: 3
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??


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

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.