【发布时间】:2015-12-19 10:30:33
【问题描述】:
实际上我是休眠中的协会新手,这是问题 是因为配置错误?
SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
我在主类中使用的上述查询也不起作用, 但它显示了同样的东西......??
休眠配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/mysql</property>
<property name="connection.user">root</property>
<property name="connection.password">tiger</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="Pojo.hbm.xml" />
<mapping resource="Address.hbm.xml"/>
</session-factory>
</hibernate-configuration>
地址实体映射
<?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="com.firoz.Pojo.Address"table="name">
<id name = "Addid" column="Addressid">
<generator class="foreign">
<param name="property">ps</param>
</generator>
</id>
<property name="roadno" column="roadno" length="10" />
<property name="Street" column="street" length="10"/>
<one-to-one name="ps" class="com.firoz.Pojo.Pojo" cascade="all"></one-to-one>
</class>
</hibernate-mapping>
Pojo 实体映射
<?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="com.firoz.Pojo.Pojo" table="name">
<id name="eid" column="id" type="java.lang.Integer"/>
<property name="ename" column="name" type="java.lang.String" />
<property name="sal" column="sal" type="java.lang.Integer" />
</class>
</hibernate-mapping>
我收到以下错误。
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.firoz.main.Test.main(Test.java:17)
Caused by: org.dom4j.DocumentException: hibernate.org Nested exception: hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 2 more
【问题讨论】:
-
你的数据库名称是“mysql”吗??
-
Hibernate 可以在本地解析 DTD(无需网络连接)。发生这种情况时您是否在离线工作?
-
是的...这是我的数据库名称.......@NewBee Developer
标签: hibernate hibernate-mapping