編集 #2 - 下部に人物クラスを追加しました。
これは私を夢中にさせています!これはマッピングの問題だと思いますが、よくわかりません。私は 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
最初のマッピング:
<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>
そして2番目のマッピング:
<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;
}
}
私はこれを理解したときに自分自身を蹴ることになると確信していますが、誰かが私に手を差し伸べることができますか? ありがとうデイブ