当前位置: 代码迷 >> Java Web开发 >> 出现以下异常如何解决 望大神指教
  详细解决方案

出现以下异常如何解决 望大神指教

热度:907   发布时间:2016-04-10 23:01:53.0
出现以下错误怎么解决 望大神指教
出现错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.text.Text.main(Text.java:17)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/domain/person.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 com.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 1 more
Caused by: org.hibernate.MappingException: class com.doamin.Person not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:401)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:334)
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
Caused by: java.lang.ClassNotFoundException: com.doamin.Person
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 15 more

hibernate配置:

<!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.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql:///test</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">123</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

    <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="show_sql">true</property>



<mapping resource="com/domain/person.hbm.xml"/>
<mapping resource="com/domain/idcade.hbm.xml"/>

</session-factory>
</hibernate-configuration>


Person配置

<?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="com.doamin">

<class name="Person" >

<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<one-to-one name="idcade"></one-to-one>

</class>

</hibernate-mapping>


idcade 配置:

<?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="com.domain">

<class name="IdCade" table="id_cade">
<id name="id">
<generator class="foreign">
  <param name="property">person</param>
</generator>

</id>
<property name="useful_life" />

<one-to-one name="person"></one-to-one>

</class>

</hibernate-mapping>

  相关解决方案