其实我是Hibernate中的新手,这是个问题 发生错误的配置?
SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
我在主类中使用的上述查询也不起作用, 但它显示了同样的事情...... ??
Hibernate配置文件
<?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 Entity Mappiing
<?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
答案 0 :(得分:0)
在地址实体映射xml文件中,您在表属性之前缺少空格。 进行以下更改并尝试:
SELECT *
FROM countries c
WHERE c.name LIKE '%$str%' OR
FIND_IN_SET(c.name, REPLACE($str, ' ', ',')) > 0
到
<class name="com.firoz.Pojo.Address"table="name">