开发者社区> 问答> 正文

hibernate创建表出错,大神快来帮帮啊? 报错

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>

展开
收起
优选2 2020-06-04 17:39:21 739 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>  

    ######我改成这样的了,但是我用main方法还是启动不了######我用的是SQLServer######

    提示很明白:

    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属性。你检查下你的配置文件呗。


    ######回复 @springsky : 用main创建跟Hibernate没关系吧?你看看你方法是不是写的有问题?mysql跟sqlserver是一样的吗?######回复 @Sprieo : 我用的是main方法创建的,创建mysql表 就可以######回复 @springsky : 自动建表语句不是在这个地方配置的 。你参考下这个位置:http://blog.csdn.net/lixuyuan/article/details/8057119######恩,我把配置文件改了,但是启动的时候不报错也不创建表。。。
    2020-06-04 18:07:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

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

相关实验场景

更多