java - Could not parse configuration: hibernate.cfg.xml caused by org.dom4j.DocumentException: Error on line 2 of document -
i not hibernate , have following problem trying follow tutorial. using hibernate 4
so have client class named helloworldclient:
public class helloworldclient { public static void main(string[] args) { session session = hibernateutil.getsessionfactory().opensession(); session.begintransaction(); message message = new message( "hello world hibernate & jpa annotations" ); session.save(message); session.gettransaction().commit(); session.close(); } } as can see class use hibernateutil retrieve hibernate session object, one:
public class hibernateutil { private static final sessionfactory sessionfactory = buildsessionfactory(); private static sessionfactory buildsessionfactory() { try { // create sessionfactory hibernate.cfg.xml configuration configuration = new configuration().configure("hibernate.cfg.xml"); return configuration.buildsessionfactory( new standardserviceregistrybuilder().applysettings( configuration.getproperties() ).build() ); } catch (throwable ex) { // make sure log exception, might swallowed system.err.println("initial sessionfactory creation failed." + ex); throw new exceptionininitializererror(ex); } } public static sessionfactory getsessionfactory() { return sessionfactory; } } and, can see, class use hibernate.cfg.xml configuration file putted root of project, one:
<?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> <!-- database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hello-world</property> <property name="connection.username">root</property> <property name="connection.password">mypswd</property> <!--sql dialect --> <property name = dialect ">org.hibernate.dialect.mysqldialect</property> <!--use annotation - based mapping metadata --> <mapping class="entity.message" /> </session-factory> </hibernate-configuration> the problem when perform application obtain error message:
info: hhh000040: configuration resource: hibernate.cfg.xml initial sessionfactory creation failed.org.hibernate.hibernateexception: not parse configuration: hibernate.cfg.xml exception in thread "main" java.lang.exceptionininitializererror @ util.hibernateutil.buildsessionfactory(hibernateutil.java:21) @ util.hibernateutil.<clinit>(hibernateutil.java:10) @ client.helloworldclient.main(helloworldclient.java:13) caused by: org.hibernate.hibernateexception: not parse configuration: hibernate.cfg.xml @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2165) @ org.hibernate.cfg.configuration.configure(configuration.java:2077) @ util.hibernateutil.buildsessionfactory(hibernateutil.java:15) ... 2 more caused by: org.dom4j.documentexception: error on line 2 of document : non è consentita una destinazione di istruzione di elaborazione corrispondente "[xx][mm][ll]". nested exception: non è consentita una destinazione di istruzione di elaborazione corrispondente "[xx][mm][ll]". @ org.dom4j.io.saxreader.read(saxreader.java:482) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2157) ... 4 more it seems can't read hibernate.cfg.xml file or this.
why? missing ? how can fix issue ?
the mapping document not valid xml. fix line 19:
<property name="dialect">org.hibernate.dialect.mysqldialect</property> other shoud work.
Comments
Post a Comment