您好我正在尝试使用mysql配置hibernate。
我使用Maven和IntelliJ来获取我的依赖项。
我的hibernate配置文件是
<?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="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">SYS</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory</property>
<mapping resource="Person.hdm.xml"></mapping>
</session-factory>
</hibernate-configuration>
我有一个映射类Person.hdm.xml
<hibernate-mapping>
<class name="Person">
<id name="FirstName"/>
</class>
</hibernate-mapping>
我得到以下堆栈..
222 [main] INFO org.hibernate.cfg.Configuration - HHH000221: Reading mappings from resource: hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at Main.<clinit>(Main.java:24)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Caused by: java.lang.NoSuchFieldError: TRACE
at org.jboss.logging.Log4jLogger.translate(Log4jLogger.java:64)
at org.jboss.logging.Log4jLogger.isEnabled(Log4jLogger.java:39)
at org.jboss.logging.Logger.logv(Logger.java:1953)
at org.hibernate.internal.CoreMessageLogger_$logger.tracev(CoreMessageLogger_$logger.java:443)
at org.hibernate.cfg.EJB3DTDEntityResolver.resolveEntity(EJB3DTDEntityResolver.java:58)
at org.apache.xerces.util.EntityResolverWrapper.resolveEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.resolveEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)
at org.hibernate.cfg.Configuration.add(Configuration.java:477)
at org.hibernate.cfg.Configuration.add(Configuration.java:473)
at org.hibernate.cfg.Configuration.add(Configuration.java:646)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:729)
at Main.<clinit>(Main.java:22)
... 3 more
非常感谢任何帮助,
谢谢, 标记
答案 0 :(得分:0)
java.lang.NoSuchFieldError:“如果应用程序试图访问或修改对象的指定字段,并且该对象不再具有该字段,则抛出该异常。”
Log4jLogger看起来是罪魁祸首,我注意到它是'org.jboss.logging'..是hibernate期待不同的版本?看起来像环境特定的记录器(即Jboss,app服务器),你在JBoss中运行它吗?