具有复合键的联接子类中的hibernate IllegalArgumentException

具有复合键的联接子类中的hibernate IllegalArgumentException,hibernate,database-design,orm,hibernate-mapping,Hibernate,Database Design,Orm,Hibernate Mapping,编辑#2-在底部添加person类 这简直快把我逼疯了!我认为这是一个映射问题,但我不确定。我对Hibernate还不熟悉,我认为使用带有复合键的连接子类会把我搞砸 打开会话时出错,消息为: Initial SessionFactory creation failed.org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.dave.test.Person.per

编辑#2-在底部添加person类

这简直快把我逼疯了!我认为这是一个映射问题,但我不确定。我对Hibernate还不熟悉,我认为使用带有复合键的连接子类会把我搞砸

打开会话时出错,消息为:

Initial SessionFactory creation failed.org.hibernate.PropertyAccessException:
IllegalArgumentException occurred calling getter of com.dave.test.Person.personId
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mkyong.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
at com.mkyong.util.HibernateUtil.<clinit>(HibernateUtil.java:8)
at com.mkyong.App.main(App.java:21)

Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling
getter of com.dave.test.Person.personId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get 
(BasicPropertyAccessor.java:198)

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:172)
... 11 more
我想当我弄明白这一点的时候,我肯定会自责的,但是有人能帮我一下吗? 谢谢
Dave

首先,
Client
类包含
personId
属性(加上getter和setter)。由于
Client
扩展了
Person
,因此它继承了
personId
属性。因此,应该删除
客户机
类中的一个


第二件事,
Client
类包含一个对
Person
的引用,除非客户机有另一个
Person
(has-a,而不是is-a),否则我认为这是错误的,可能会导致问题(尽管没有在XML中映射)。

请提供
Person
类内容。好主意!我编辑了这篇文章,并在底部添加了person类。看起来您遗漏了person类声明和私有属性(这些是我所关注的)。我无法重现这个问题。也许您可以提供一个具有最小配置的小项目来重现问题/异常(类、映射文件、配置)。你可以使用免费的托管服务。很好,我更改了客户端并删除了personId getter和setter以及Person引用,但仍然得到相同的错误:2012-07-21_10:59:19.121错误o.h.property.BasicPropertyAccessor-类中的IllegalArgumentException:com.dave.test.Person,属性的getter方法:personId初始会话工厂创建失败。org.hibernate.PropertyAccessException:IllegalArgumentException在调用线程“main”java.lang.ExceptionInInitializeError中的com.dave.test.Person.personId异常的getter时发生。上面的注释格式不正确,简短的回答是修复不起作用。@Dave我无法使用您提供的代码重现问题-它毫无例外地起作用。您需要提供一组最小的源代码来重现问题(在单独的项目中尝试)。Nicolae,谢谢您的建议。我回去重做了这个项目,基本上是从头开始的,现在它可以工作了。总有一天,当我感到无聊的时候,也许我会回去试着找出错误在哪里。
<hibernate-mapping>
  <class name="com.mkyong.stock.Appointment" table="appointment" catalog="physdb">
    <composite-id name="id" class="com.dave.test.AppointmentId">
        <key-property name="personId" type="int">
            <column name="person_id" />
        </key-property>
        <key-property name="apptdate" type="timestamp">
            <column name="apptdate" length="19" />
        </key-property>
    </composite-id>
    <many-to-one name="client" update="false" insert="false" fetch="select">
        <column name="person_id" not-null="true" />
    </many-to-one>
    <property name="location" type="string">
        <column name="location" length="45" not-null="true" />
    </property>
    <property name="fee" type="big_decimal">
        <column name="fee" precision="7" />
    </property>
    <property name="paid" type="big_decimal">
        <column name="paid" precision="7" />
    </property>
    <property name="serviceRendered" type="boolean">
        <column name="service_rendered" not-null="true" />
    </property>
  </class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.dave.test.Person" table="person" catalog="physdb">
    <id name="personId" >
        <column name="person_id" />
        <generator class="identity" />
    </id>
    <property name="firstName" type="string">
        <column name="first_name" length="45" not-null="true" />
    </property>
    <property name="lastName" type="string">
        <column name="last_name" length="45" not-null="true" />
    </property>
    <property name="phone" type="string">
        <column name="phone" length="15" />
    </property>
    <property name="cellPhone" type="string">
        <column name="`cell_phone`" length="15" />
    </property>

    <joined-subclass name="com.dave.test.Client" table="client" extends="Person">
            <key column="person_id" />
    <set name="appointments" cascade="all" inverse="true" lazy="false">
        <key column="person_id"/>
        <one-to-many class="com.dave.test.Appointment"/>
    </set>      

    <property name="complaint" type="string">
        <column name="complaint" not-null="true" />
    </property>
    <property name="notes" type="string">
        <column name="notes" not-null="false" />
    </property>
    <property name="doctor" type="string">
        <column name="doctor" not-null="false" />
    </property>
    </joined-subclass>

<joined-subclass name="com.dave.test.Therapist" table="therapist" extends="Person">
            <key column="person_id" />

    <property name="school" type="string">
        <column name="school" not-null="false" />
    </property>
    <property name="specialties" type="string">
        <column name="notes" not-null="false" />
    </property>
    <property name="hiredate" type="date">
        <column name="hiredate" not-null="true" />
    </property>
</joined-subclass>


 </class>
</hibernate-mapping>
public class Client extends Person implements java.io.Serializable {

private int personId;
private Person person;
private String complaint;
private String notes;
private String doctor;
private Set appointments = new HashSet();
public int getPersonId() {
    return this.personId;
}

public void setPersonId(int personId) {
    this.personId = personId;
}

}

public class Appointment implements java.io.Serializable {

private AppointmentId id;
private Client client;
private String location;
private BigDecimal fee;
private BigDecimal paid;
private boolean serviceRendered;

public AppointmentId getId() {
    return this.id;
}

public void setId(AppointmentId id) {
    this.id = id;
}
}

public class AppointmentId implements java.io.Serializable {

private int personId;
private Date apptdate;

public int getPersonId() {
    return this.personId;
}

public void setPersonId(int personId) {
    this.personId = personId;
}

}

public class Person implements java.io.Serializable {

private int personId;
private String firstName;
private String lastName;
private String phone;
private String cellPhone;
private Therapist therapist;
private Client client;


public int getPersonId() {
    return this.personId;
}

public void setPersonId(int personId) {
    this.personId = personId;
}
}