当前位置: 代码迷 >> Java Web开发 >> org.hibernate.MappingException: entity class not found: com.
  详细解决方案

org.hibernate.MappingException: entity class not found: com.

热度:274   发布时间:2016-04-17 01:04:06.0
struts2+hibernate配置异常问题2
hibernate.cfg.xml:

<?xml version='1.0' encoding='UTF-8'?>
  <!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  <!-- Generated by MyEclipse Hibernate Tools. -->
  <hibernate-configuration>
  <session-factory>
  <!--Examda提示:数据库用户名-->
  <property name="connection.username">root</property>
  <!--数据库URL-->
  <property name="connection.url">
  jdbc:mysql://localhost:3306/logindb
  </property>
  <!--dialect,每个数据库对应的Dialet匹配其平台特性-->
  <property name="dialect">
  org.hibernate.dialect.MySQLDialect
  </property>
  <!--数据库密码-->
  <property name="connection.password">0</property>
  <!--数据库驱动-->
  <property name="connection.driver_class">
  com.mysql.jdbc.Driver
  </property>
  <property name="hibernate.use_out_join">True</property>
  <property name="hibernate.c3p0.max_size">20</property>
  <property name="hibernate.c3p0.min_size">1</property>
  <property name="hibernate.c3p0.timeout">5000</property>
  <property name="hibernate.c3p0.max_statements">100</property>
  <property name="hibernate.c3p0.idle_test_period">3000</property>
  <property name="hibernate.c3p0.acqiure_increment">2</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <mapping resource="com/test/model/logindb.hbm.xml" />
  </session-factory>
  </hibernate-configuration>


logindb.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>
  <class name="com.test.model.Login" table="customer" >
  <id name="customerId" type="string" column="customerId" >
  <generator class="identity" />
  </id>
  <property name="password" type="string">
  <column name="password" length="20" />
  </property>
  </class>
</hibernate-mapping>



/practice/src/com/test/model/Login.java:


package com.test.model;

public class Login {

private String customerId;

private String password;

public void setPassword(String password) {
this.password = password;
}

public String getPassword() {
return password;
}

public void setCustomerId(String customerId) {
this.customerId = customerId;
}

public String getCustomerId() {
return customerId;
}

}

action:

  Configuration conf = new Configuration().configure();
SessionFactory sf = conf.buildSessionFactory();
Session sess = sf.openSession();

第二行异常了。


org.hibernate.MappingException: entity class not found: com.test.model.Login
org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
  相关解决方案