异常在线程" main " org hibernate。 InvalidMappingException:不能解析映射文档从资源pojo /用户hbm xml

硕硕 发布于 2012/10/07 13:54
阅读 2K+
收藏 0

INFO: HHH000041: Configured SessionFactory: null
十月 07, 2012 1:45:03 下午 org.hibernate.cfg.Configuration$MappingsImpl addImport
INFO: HHH000071: Duplicate import: User -> User
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource pojo/User.hbm.xml
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3415)
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3404)
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3392)
 at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
 at pojo.userTest.main(userTest.java:23)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping User
 at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2580)
 at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174)
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3412)
 ... 5 more

-----------------------------------------------------------------------------------------------------------

package pojo;
// Generated 2012-10-6 18:52:12 by Hibernate Tools 3.2.2.GA

/**
 * User generated by hbm2java
 */
public class User implements java.io.Serializable {

 private int id;
 private String name;
 private String password;

 public User() {
 }

 public User(int id) {
  this.id = id;
 }

 public User(int id, String name, String password) {
  this.id = id;
  this.name = name;
  this.password = password;
 }

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

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

 public String getName() {
  return this.name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public String getPassword() {
  return this.password;
 }

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

}
----------------------------------------------------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-10-6 18:52:12 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
    <class name="User" table="user" catalog="shoushou">
        <id name="id" type="int">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="name" length="11" />
        </property>
        <property name="password" type="string">
            <column name="password" length="11" />
        </property>
    </class>
</hibernate-mapping>
--------------------------------------------------------------------------------------------------------

<?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">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1/shoushou</property>
        <property name="hibernate.connection.username">root</property>   
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping resource="pojo/User.hbm.xml " />
    </session-factory>
</hibernate-configuration>

------------------------------------------------------------------------------------------------------------

package pojo;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import pojo.User;


public class userTest {
 
 public static void main(String[] args) {
 
  Configuration cfg = new Configuration();

  cfg.configure();

  ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

  SessionFactory sf = cfg.configure().buildSessionFactory(serviceRegistry); 
  
  User user = new User();
  user.setId(1);
  user.setName("ax");
  user.setPassword("aqe");
  Session session = sf.openSession();
  Transaction tx=session.beginTransaction();
  
  session.save(user);
 tx.commit();
  session.close();
 
  sf.close();
 }

 
}

用的是hibernate4.17的全部包和MYSQL  eclipse

加载中
0
_金角大王_
_金角大王_
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
	
	<class name="cc.model.Skill">
		<id name="skillId">
			<generator class="native"></generator>
		</id>
		<property name="situation" length="100"/>
		<property name="question" length="200"/>
		<property name="wordArt" length="100"/>
		<property name="keyword" length="100"/>
	</class>

</hibernate-mapping>


0
JustForFly
JustForFly

<class name="User" table="user" catalog="shoushou">

name应该加上完整路径名吧

<class name="pojo.User" table="user" catalog="shoushou">

返回顶部
顶部