hibernate创建表出错,大神快来帮帮啊? 400 报错 SLF4J: This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1493)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1434)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1011)
at com.zhuoshang.model.gggl.GgTypeEntity.main(GgTypeEntity.java:122)
Caused by: org.xml.sax.SAXParseException: Attribute "value" must be declared for element type "property".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1275)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1940)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:785)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1490)
... 8 more
我的配置文件
<?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="datasource">
org.apache.commons.dbcp.BasicDataSource
</property>
<property name="connection.url">
jdbc:sqlserver://192.168.0.107:1433;databaseName=baiyi
</property>
<property name="connection.username">sa</property>
<property name="connection.password">qwe123</property>
<property name="connection.driver_class"> com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="format_sql">true</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<mapping class="com.zhuoshang.model.gggl.GgTypeEntity" />
</session-factory>
</hibernate-configuration>
看这句 Caused by: org.xml.sax.SAXParseException: Attribute "value" must be declared for element type "property".
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/> 是不是写错了
应该这样:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
提示很明白:
Exception in thread "main" org.hibernate.MappingException: invalid configuration Caused by: org.xml.sax.SAXParseException: Attribute "value" must be declared for element type "property".
意思是说,你的Hibernate配置文件有问题,映射的时候,property元素必须要有value属性。你检查下你的配置文件呗。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。