开发者社区> 问答> 正文

大神快来帮帮啊! 关于 hibernate创建表出错

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>

展开
收起
爵霸 2016-03-04 14:50:40 1932 0
1 条回答
写回答
取消 提交回答
  • 看这句

     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>  
    2019-07-17 18:52:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载