gpt4 book ai didi

java - 4.0 XSD 上的 Hibernate 异常

转载 作者:行者123 更新时间:2023-11-30 11:30:14 27 4
gpt4 key购买 nike

第一次使用 Hibernate,遇到一个奇怪的错误。我使用的是 4.2.3 Final 版本,并且喜欢使用 4.0 XSD 架构,但如果这是让它工作所需要的,我将使用 3.0 DTD .

我的司机:

public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.configure("hibernate/cfg/hibernate.cfg.xml");
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration
.getProperties());
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
Session session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();

User user = new User("Dr.", "Sylvester", "McMonkey", "McBean", "IV");

session.save(user);
tx.commit();
session.close();
}

我的hibernate.cfg.xml 文件,位于我的项目src/main/config/hibernate/cfg 下:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://my-server:3306/my_db</property>
<property name="hibernate.connection.username">myuser</property>
<property name="hibernate.connection.password">password</property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>

<property name="hbm2ddl.auto">validate</property>

<mapping resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Eclipse 给我的堆栈跟踪:

Jul 27, 2013 9:10:08 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jul 27, 2013 9:10:08 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.3.Final}
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate/cfg/hibernate.cfg.xml
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate/cfg/hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2070)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1987)
at com.apponomical.adaptors.datasource.HibernateDriver.main(HibernateDriver.java:15)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:387)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:321)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:226)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3080)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:899)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2067)
... 2 more

想法?想法?建议?提前致谢!

最佳答案

validator 未找到架构。 xsi:schemaLocation 属性告诉它在与您正在验证的配置文档 (.../src/main/config/hibernate/cfg) 相同的目录中查找模式文档 hibernate-configuration-4.0.xsd。那是你拥有它的地方吗?

关于java - 4.0 XSD 上的 Hibernate 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17898320/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com