Hibernateはリソースファイルからマッピングを解析できません
この2,3日、Hibernateがリソースファイルからマッピングを解析できないという問題が発生し、次のようにエラーが発生しました.
他のプロファイルに問題があるかどうかを確認するためにhbm.xmlのマッピングは私のhibernateから.cfg.xml除去、personのみマッピング.hbm.xmlはpersonテーブルの作成に成功しました.Googleで検索したところによると、基本的にはパッケージがあるかどうかをチェックして、頭"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">間違いではないか、idプライマリ・キーの構成など.しかし、これらに問題があれば、私の前のpersonテーブルが成功するはずがないでしょう.きっと私のpersonMessages.hbm.xml構成に問題があると思います.しかし、私は長い間探していましたが、見つかりませんでした.
これは私の进捗状况がここまで突然止まって、これは私をとても気がふさいで、もし誰かがこの招待状を见ることができるならば、私を手伝って、何の问题があるかを见抜いてください.ありがとうございます!関連する構成を以下のように貼り付けます.
1.hibernate.cfg.xml:
2.personMessages.hbm.xml:
3.personMessages.java:
4.CreateTabel.java:
以上の必要なjarパケットはhibernateにインポートする.cfg.xmlファイルから削除
ではpersonテーブルの作成に成功
その中でperson.hbm.xmlの構成は次のとおりです.
このような問題が発生した場合は、何が原因なのか、どのように変更すれば解決できるのか教えてください.
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource wei/college/bean/personMessages.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:523)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at wei.college.bean.CreateTable.main(CreateTable.java:8)
Caused by: org.hibernate.PropertyNotFoundException: field [contents;] not found on wei.college.bean.PersonMessages
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:112)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:119)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:127)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2164)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2141)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:424)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:465)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:520)
... 7 more
他のプロファイルに問題があるかどうかを確認するためにhbm.xmlのマッピングは私のhibernateから.cfg.xml除去、personのみマッピング.hbm.xmlはpersonテーブルの作成に成功しました.Googleで検索したところによると、基本的にはパッケージがあるかどうかをチェックして、頭"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">間違いではないか、idプライマリ・キーの構成など.しかし、これらに問題があれば、私の前のpersonテーブルが成功するはずがないでしょう.きっと私のpersonMessages.hbm.xml構成に問題があると思います.しかし、私は長い間探していましたが、見つかりませんでした.
これは私の进捗状况がここまで突然止まって、これは私をとても気がふさいで、もし誰かがこの招待状を见ることができるならば、私を手伝って、何の问题があるかを见抜いてください.ありがとうございます!関連する構成を以下のように貼り付けます.
1.hibernate.cfg.xml:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/college
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="wei/college/bean/person.hbm.xml" />
<mapping resource="wei/college/bean/personMessages.hbm.xml" />
</session-factory>
</hibernate-configuration>
2.personMessages.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="wei.college.bean">
<!-- -->
<class name="PersonMessages">
<id name="id" type="integer">
<generator class="native"></generator>
</id>
<property name="realname"></property>
<property name="sex"></property>
<property name="birthday"></property>
<property name="age"></property>
<property name="height"></property>
<property name="weight"></property>
<property name="national"></property>
<property name="marital"></property>
<property name="address"></property>
<property name="degree"></property>
<property name="department"></property>
<property name="professional"></property>
<property name="political"></property>
<property name="certificateType"></property>
<property name="certificateNum"></property>
<property name="email"></property>
<property name="phone"></property>
<property name="interest"></property>
<property name="contents;"></property>
<property name="imageUrl"></property>
<one-to-one name="person" class="Person"></one-to-one>
</class>
</hibernate-mapping>
3.personMessages.java:
package wei.college.bean;
public class PersonMessages {
private Person person;//
private int id;//ID
private String realname;//
private String sex;//
private String birthday;//
private int age;//
private String height;//
private String weight;//
private String national;//
private String marital;//
private String address;//
private String degree;//
private String department;//
private String professional;//
private String political;//
private String certificateType;//
private String certificateNum;//
private String email;//Email
private String phone;//
private String interest;//
private String contents;//
private String imageUrl;//
//set get ......
}
4.CreateTabel.java:
package wei.college.bean;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class CreateTable {
public static void main(String[] args) {
Configuration conf = new Configuration().configure();
SchemaExport se = new SchemaExport(conf);
se.create(true, true);
}
}
以上の必要なjarパケットはhibernateにインポートする.cfg.xmlファイルから削除
その中でperson.hbm.xmlの構成は次のとおりです.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="wei.college.bean">
<!-- -->
<class name="Person" >
<id name="id" type="integer">
<generator class="native"></generator>
</id>
<property name="username"></property>
<property name="password"></property>
<property name="email"></property>
<one-to-one name="personMess" class="PersonMessages" ></one-to-one>
</class>
</hibernate-mapping>
このような問題が発生した場合は、何が原因なのか、どのように変更すれば解決できるのか教えてください.