【发布时间】:2015-04-16 09:40:41
【问题描述】:
我尝试了一个多小时才发现错误,但我仍然无法:
cd C:\Users\zimnyk\Documents\NetBeansProjects\kwestionariusz; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_40" cmd /c "\"\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath com.mycompany.kwestionariusz.main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_40\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.0.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
------------------------------------------------------------------------
Building kwestionariusz 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ kwestionariusz ---
kwi 16, 2015 11:29:46 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
kwi 16, 2015 11:29:46 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
kwi 16, 2015 11:29:46 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
16, 2015 11:29:46 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
kwi 16, 2015 11:29:46 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
kwi 16, 2015 11:29:46 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
kwi 16, 2015 11:29:46 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
kwi 16, 2015 11:29:46 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Osoba.hbm.xml
kwi 16, 2015 11:29:46 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mycompany.kwestionariusz.util.NewHibernateUtil.<clinit>(NewHibernateUtil.java:31)
at com.mycompany.kwestionariusz.main.main(main.java:20)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)
at org.hibernate.cfg.Configuration.add(Configuration.java:516)
at org.hibernate.cfg.Configuration.add(Configuration.java:512)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.AnnotationConfiguration.addResource(AnnotationConfiguration.java:123)
at org.hibernate.cfg.AnnotationConfiguration.addResource(AnnotationConfiguration.java:46)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:213)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:46)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:201)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:46)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:183)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:46)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:177)
at com.mycompany.kwestionariusz.util.NewHibernateUtil.<clinit>(NewHibernateUtil.java:27)
... 1 more
Caused by: org.dom4j.DocumentException: Error on line 13 of document : The value of attribute "column" associated with an element type "null" must not contain the '<' character. Nested exception: The value of attribute "column" associated with an element type "null" must not contain the '<' character.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:325)
... 22 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.478s
Finished at: Thu Apr 16 11:29:47 CEST 2015
Final Memory: 8M/106M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project kwestionariusz: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException]
这是错误的样子,我的映射文件:
<?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.mycompany.kwestionariusz.Osoba" table="DaneOsobowe">
<property name="imie" column="Imie"/>
<property name="nazwisko" column="Nazwisko"/>
<property name="telefon" column="Telefon"/>
<property name="email" column="Email"/>
<property name="uczelnia" column="Uczelnia"/>
<property name="doswiadczenie" column="Doswiadczenie"/>
<property name="zainteresowania" column="Zainteresowania"/>
<property name="skadSlyszal" column="SkadSlyszal"/>
</class>
</hibernate-mapping>
这是我的配置文件:
<?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>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">test</property>
<mapping resource="Osoba.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我第一次使用 maven 和 hibernate,所以这个错误对我来说也很糟糕,你能帮帮我吗?
主文件第 20 行是:
Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
NewJavaUtil 的 ~31 行是:
}
catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
【问题讨论】:
-
而不是使用 println() 我真的会使用 ex.printStackTrace() 来获取有关异常的更多信息。并且请不要使用 ExceptionInInitializerError,该错误具有非常特定的含义,而这不是它(您可以在 javadocs 中查找)
-
我将
添加到将文件映射到第 5 行,它有助于解决一个错误,但新的错误是:... 1更多原因:org.dom4j.DocumentException:文档第 5 行出错:与元素类型“null”关联的属性“table”的值不得包含“
标签: java hibernate maven mapping