大家好,我是hibernate的初学者,我知道这里有很多类似的问题。我试图从他们那里解决,但我做不到。我还试图在dtd中将SYSTEM从PUBLIC更改为,但是它不起作用。我用谷歌搜索它,但是到处都显示dtd语句错误。
这是我的配置文件。
<!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>
我尝试将版本3.0更改为4.0,因为我正在使用hibernate版本4.3.6,但仍无法正常工作。请帮帮我。
这是我的userDetails类。
软件包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; } }
这些我已添加到项目中的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
这是我在运行应用程序时得到的
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
我更新了您提到的dtd。非常感谢。
我改变了我的 ****标签。 则表明代码之前空白出现错误。
我解决了它,然后向我显示了可访问的数据库hibernate错误。我什至尝试了很多,即使我没有重新安装我的Wamp服务器。
最后,我创建了一个新数据库并更改了hibernate.cfg.xml文件。
这是我的文件,运行起来很酷…
<?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>