These two days want to look at hibernate things, follow the official website tutorial do their own, by the official website of the configuration file to the pit.
There are two places to note, if it is according to the official website of cheese Note, one is Hibernate's head XSD validation file, not modified into a DTD read Hibernate.cxf.xml will
Throw could not parse configuration:/hibernate.cfg.xml or org.hibernate.MappingException:invalid configuration exception Oh.
1 <hibernate-configuration2 xmlns= "Http://www.hibernate.org/xsd/hibernate-configuration"3 xsi:schemalocation= "Http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"4 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">5 6 change to the following format7 <!DOCTYPE hibernate-configuration Public8 "-//hibernate/hibernate Configuration DTD 3.0//en"9 "Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
There are other classmates who throw content with the element type "Session-factory" must match "(property*,mapping*, (Class-cache|collection-cache) *,event*,listener*)".
There are two possible causes for this anomaly:
There are errors in the order of the configuration files in 1.hibernate, and the <property>,<mapping>, <event> and <listener> tags are configured sequentially:
1 Note the order between the property, mapping, event, and listener2 < Propertyname= "Connection.driver_class">Com.mysql.jdbc.Driver</ Property>3 < Propertyname= "Connection.url">Jdbc:mysql://localhost/hibernate</ Property>4 5 6 7 <Mappingclass= "Com.yami.hibernate.pojo.SingleUser" />8 <MappingResource= "Org/hibernate/tutorial/domain/event.hbm.xml"/>9 Ten One <Event></Event> A <Listener></Listener>
2. If it is not a sequential problem, there is only one possibility, your configuration file may be copied from the Web page or other through the Format tool, some encoding is not converted, causing Hibernate to read the configuration file will also throw this error, the following gives a configurable profile (which is a benefit haha),
Copy it to your project and reconfigure it to:
<?XML version= "1.0" encoding= "Utf-8"?><!DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://hibernate . Sourceforge.net/hibernate-configuration-3.0.dtd "><hibernate-configuration> <session-factory> <!--Database Connection Settings - < Propertyname= "Connection.driver_class">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Connection.url">Jdbc:mysql://localhost/hibernate</ Property> < Propertyname= "Connection.username">Erik</ Property> < Propertyname= "Connection.password">Test</ Property> <!--JDBC Connection pool (use the built-in) - < Propertyname= "Connection.pool_size">1</ Property> <!--Disable the Second-level cache - < Propertyname= "Cache.provider_class">Org.hibernate.cache.internal.CollectionCacheInvalidator</ Property> <!--Echo all executed SQL to stdout - < Propertyname= "Show_sql">True</ Property> <!--Drop and re-create the database schema on startup - < Propertyname= "Hbm2ddl.auto">Create</ Property> <!--SQL dialect - < Propertyname= "dialect">Org.hibernate.dialect.MySQLDialect</ Property> <!--Names The annotated entity class - <Mappingclass= "Com.yami.hibernate.pojo.SingleUser" /> </session-factory></hibernate-configuration>
Originally thought that the hibernate official online example should be no problem, the result of the problem constantly, too believe the official online code, got a long time, only to find that the format of XML is problematic.
Always think it is their own configuration file where the wrong, how to see no problem, to the end only to find that they have copied the official web page configuration file format has problems, it seems sometimes can not too believe the official website AH.
Hibernate.cxf.xml profile resolution content must match "(property*,mapping*, (Class-cache|collection-cache) *,event*,listener*)"