Hibernate无法解析配置:/hibernate.cfg.xml [英] Hibernate Could not parse configuration: /hibernate.cfg.xml

查看:111
本文介绍了Hibernate无法解析配置:/hibernate.cfg.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是冬眠的初学者,我知道这里有很多类似的问题。我试图解决他们,但我不能。
我也尝试在Dtd中将PUBLIC更改为SYSTEM,但它不起作用。
我搜索了它,但在任何地方都显示dtd语句错误。

这是我的配置文件。

 <!DOCTYPE hibernate-mapping PUBLIC 
- // Hibernate / Hibernate映射DTD 3.0 // EN
http:// www。 hibernate.org/dtd/hibernate-mapping-3.0.dtd\">
< hibernate-configuration>
< session-factory>
< property name =show_sql> true< / property>
< property name =connection.driver_class> com.mysql.jdbc.Driver / property>
< property name =connection.url> jdbc:mysql:// localhost:3306 / hibernate< / property>
< property name =username> root< / property>
< property name =password>< / property>
< property name =connection.pool_size> 1< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =hbm2ddl.auto>更新< / property>
< mapping class =org.hibernate.src.userDetails/>
< / session-factory>
< / hibernate-configuration>

我试图将版本3.0更改为4.0,因为我使用的是休眠版本4.3.6
但仍然不起作用。
请帮助我。



这是我的userDetails类..



package org.hibernate .src;

  @Entity 
public class userDetails {
@Id
private int userId ;
private String userName;
@Embedded
私有地址;


公共地址getAddress(){
返回地址;
}

public void setAddress(Address address){
this.address = address;
}

public int getUserId(){
return userId;
}

public String getUserName(){
return userName;
}
public void setUserName(String userName){
this.userName = userName;
}
public void setUserId(int userId){
this.userId = userId;

}


}

这些jar文件已添加到我的项目中:

  lib \jpa\hibernate-entitymanager-4.3.6.Final .jar 
lib\required\antlr-2.7.7.jar
lib\required\dom4j-1.6.1.jar
lib\required\hibernate-commons- annotations-4.0.5.Final.jar
lib \required\hibernate-core-4.3.6.Final.jar
lib\required\hibernate-jpa-2.1-api-1.0。 0.Final.jar
lib\required\jandex-1.1.0.Final.jar
lib\required\javassist-3.18.1-GA.jar
lib\ required \jboss-logging-3.1.3.GA.jar
lib\required\jboss-logging-annotations-1.2.0.Beta1.jar
lib\required\jboss-transaction -api_1.2_spec-1.0.0.Final.jar

这就是我在运行应用程序

  2014年10月13日下午4点24分47秒
org.hibernate.annotations.common.reflection.java .JavaReflectio nManager< clinit>
INFO:HCANN000001:Hibernate Commons Annotations {4.0.5.Final}
Oct 13,2014 4:24:47 PM org.hibernate.Version logVersion
INFO:HHH000412:Hibernate Core {4.3 .6.Final}
Oct 13,2014 4:24:47 PM org.hibernate.cfg.Environment< clinit>
INFO:HHH000206:找不到hibernate.properties
2014年10月13日下午4时24分47秒org.hibernate.cfg.Environment buildBytecodeProvider
INFO:HHH000021:字节码提供程序名称:javassist
Oct 13,2014 4:24:47 PM org.hibernate.cfg.Configuration configure
INFO:HHH000043:从资源配置:/hibernate.cfg.xml
2014年10月13日4:24: 47下午org.hibernate.cfg.Configuration getConfigurationInputStream
INFO:HHH000040:配置资源:/hibernate.cfg.xml
线程main中的异常org.hibernate.HibernateException:无法分析
配置:/hibernate.cfg.xml $ b $在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163)
在org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
在org.hibernate.cfg.Configuration.configure(Configuration.java:2054)
在org.hibernate.test.userTest.main(userTest.java:18)
导致:org .dom4j.DocumentException:文档的第4行出现错误:内容不是
允许在序言中。嵌套异常:序言中不允许使用内容。
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
... 3更多


解决方案

我更新了我的dtd。非常感谢。



我更改了我的 标记。那么它会在标签前显示一个空白的错误。



我解决了它,然后它向我显示可访问数据库休眠的错误。我尝试了很多,即使我重新安装了我的wamp服务器,尽管它没有工作。



最后,我创建了一个新数据库并更改了我的hibernate.cfg.xml文件。



这是我工作得很酷的文件...

 < xml version =1.0encoding =utf-8?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0。 DTD>
< hibernate-configuration>
< session-factory>
< property name =show_sql> true< / property>
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.url> jdbc:mysql:// localhost / test< / property>
< property name =username> root< / property>
< property name =password/>
< property name =connection.pool_size> 1< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =hbm2ddl.auto>更新< / property>
< mapping class =org.hibernet.src.userDetails>< / mapping>
< / session-factory>
< / hibernate-configuration>


Hey guys I am beginner for the hibernate and I know there are so many similar questions here. I tried to solve from them but I could not. I also tried to change SYSTEM from PUBLIC in dtd but its not working. I googled for it but everywhere it showing for the dtd statement error.

This is my configuration file.

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
   <hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver/property> 
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property> 
<property name="username">root</property> 
<property name="password"></property>
<property name="connection.pool_size">1</property>  
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="hbm2ddl.auto">update</property>
<mapping class="org.hibernate.src.userDetails" /> 
</session-factory>
</hibernate-configuration>

I tried to change the version 3.0 to 4.0 as I am using hibernate version 4.3.6 but still its not working. please help me out.

This is my userDetails class..

package org.hibernate.src;

@Entity
public class userDetails {
@Id
private int userId ;
private String userName;
@Embedded
private Address address;


public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

public int getUserId() {
    return userId;
}

public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}
public void setUserId(int userId) {
    this.userId = userId;

}


}

These jar files I have added to my project:

lib\jpa\hibernate-entitymanager-4.3.6.Final.jar
lib\required\antlr-2.7.7.jar
lib\required\dom4j-1.6.1.jar
lib\required\hibernate-commons-annotations-4.0.5.Final.jar
lib\required\hibernate-core-4.3.6.Final.jar
lib\required\hibernate-jpa-2.1-api-1.0.0.Final.jar
lib\required\jandex-1.1.0.Final.jar
lib\required\javassist-3.18.1-GA.jar
lib\required\jboss-logging-3.1.3.GA.jar
lib\required\jboss-logging-annotations-1.2.0.Beta1.jar
lib\required\jboss-transaction-api_1.2_spec-1.0.0.Final.jar

This is what I am getting while running the application

Oct 13, 2014 4:24:47 PM      
 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
 INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
 Oct 13, 2014 4:24:47 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
Oct 13, 2014 4:24:47 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Oct 13, 2014 4:24:47 PM org.hibernate.cfg.Environment buildBytecodeProvider  
INFO: HHH000021: Bytecode provider name : javassist
Oct 13, 2014 4:24:47 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Oct 13, 2014 4:24:47 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 
 Exception in thread "main" org.hibernate.HibernateException: Could not parse     
configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)
at org.hibernate.test.userTest.main(userTest.java:18)
Caused by: org.dom4j.DocumentException: Error on line 4 of document  : Content is not    
allowed in prolog. Nested exception: Content is not allowed in prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
... 3 more

解决方案

I updated my dtd as u mentioned. thank you so much.

I changed my tag. then it was showing an error for white space bfore the tag.

i solved it then it was showing me an error for accessible database hibernate. i tried a lot even i reinstall my wamp server, though it didnt work.

finally i create a new database and changed my hibernate.cfg.xml file.

this is my file which is working cool...

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
<property name="connection.url">jdbc:mysql://localhost/test</property> 
<property name="username">root</property> 
<property name="password" /> 
<property name="connection.pool_size">1</property>  
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="hbm2ddl.auto">update</property>
<mapping class="org.hibernet.src.userDetails" ></mapping> 
</session-factory>
</hibernate-configuration>

这篇关于Hibernate无法解析配置:/hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆