gpt4 book ai didi

java - org.h2.jdbc.JdbcSQLException : Schema "DBO" not found

转载 作者:行者123 更新时间:2023-12-01 22:51:34 26 4
gpt4 key购买 nike

这是 Hibernate version mismatch in WildFly 10.0 的后续问题。

为了完整起见,简要重述问题。我有2个项目,一个是普通的java项目(带有maven):core,另一个是非maven动态Web项目:webapi。后者充当核心之上的休息层。

core 使用 hibernate 没有任何问题。它定义了 persistence.xml(在 src/META-INF/ 内),如下所示:

<?xml version="1.0" encoding="utf-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">

<persistence-unit name="app" transaction-type="RESOURCE_LOCAL">

<class>data.entities.Anything</class>
<class>data.entities.Something</class>

<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost;databaseName=AppDb"></property>
<property name="javax.persistence.jdbc.user" value="****"></property>
<property name="javax.persistence.jdbc.password" value="****"></property>
<property name="hibernate.default_schema" value="dbo"></property>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"></property>
<property name="hibernate.hbm2ddl.auto" value="update"></property>
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2.4.Final" />
</properties>
</persistence-unit>
</persistence>

corewebapi现在都使用hibernate-core 5.2.4.Final,使用maven和WildFly模块安装,如here所述,分别。

但是,现在当我将 webapi 部署到 WildFly 10.0 时,出现以下错误:

[org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "webapi.war" (runtime-name: "webapi.war")

[org.jboss.as.jpa] (MSC service thread 1-1) WFLYJPA0002: Read persistence.xml for app

[org.jboss.as.jpa] (ServerService Thread Pool -- 67) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'webapi.war#app'

[org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 67) HHH000204: Processing PersistenceUnitInfo [ name: app ...]

[org.hibernate.orm.deprecation] (ServerService Thread Pool -- 67) HHH90000001: Found usage of deprecated setting for specifying Scanner [hibernate.ejb.resource_scanner]; use [hibernate.archive.scanner] instead

[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0004: Deploying JDBC-compliant driver class com.microsoft.sqlserver.jdbc.SQLServerDriver (version 6.0)

[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0018: Started Driver service with driver-name = webapi.war_com.microsoft.sqlserver.jdbc.SQLServerDriver_6_0

[org.jboss.as.jpa] (ServerService Thread Pool -- 67) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'webapi.war#app'

[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 67) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect

[org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 67) Envers integration enabled? : true

[org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl] (ServerService Thread Pool -- 67) GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:524) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:470) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:273) at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:203) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:177) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:66) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:309) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:877) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) at org.jboss.threads.JBossThread.run(JBossThread.java:320)

Caused by: org.h2.jdbc.JdbcSQLException: Schema "DBO" not found; SQL statement: create table dbo.Anythings (Id binary(255) not null, CreatedOn datetime not null, IsActive bit, primary key (Id)) [90079-173] at org.h2.message.DbException.getJdbcSQLException(DbException.java:331) at org.h2.message.DbException.get(DbException.java:171) at org.h2.message.DbException.get(DbException.java:148) at org.h2.command.Parser.getSchema(Parser.java:616) at org.h2.command.Parser.getSchema(Parser.java:623) at org.h2.command.Parser.parseCreateTable(Parser.java:5302) at org.h2.command.Parser.parseCreate(Parser.java:3873) at org.h2.command.Parser.parsePrepared(Parser.java:324) at org.h2.command.Parser.parse(Parser.java:279) at org.h2.command.Parser.parse(Parser.java:251) at org.h2.command.Parser.prepareCommand(Parser.java:218) at org.h2.engine.Session.prepareLocal(Session.java:428) at org.h2.engine.Session.prepareCommand(Session.java:377) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1138) at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:168) at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:156) at org.jboss.jca.adapters.jdbc.WrappedStatement.execute(WrappedStatement.java:198) at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ... 20 more

有什么办法可以纠正这个问题吗?

更新:我认为,它无法连接数据库。当我使用 hibernate.hbm2ddl.auto 作为 validate 而不是 update 时,出现以下错误:

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [dbo.Anythings]

其他信息:我已经将 sqljdbc42.jar 放入 wildfly-10.0.0.Final\modules\system\layers\base\com\microsoft\sqlserver\mainmodule.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!-- JDBC Drivers module.xml file to configure your JDBC drivers-->

<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver" slot="main">
<resources>
<resource-root path="sqljdbc42.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

我还尝试将 sqlserver 添加为 standalone.xml 中的全局子系统:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="com.microsoft.sqlserver" slot="main"/>
</global-modules>
...
</subsystem>

但是,这些都不起作用。

最佳答案

这似乎是由您指定数据库连接的方式引起的。在 EE 环境中,您应该使用数据源定义,指定为 jta-data-sourcenon-jta-data-source在你的persistence.xml 。如 JPA 2.1 规范(第 8.2.1.5 章)中所述,如果您未指定其中任何一个,您的 Wildfly 将使用其默认数据源(名为 ExampleDS)部署您的应用程序,该数据源使用 h2 内存数据库。通过属性(javax.persistence.jdbc.url 等)的连接参数将被忽略,因为它们适用于 Java SE 环境而不是 Java EE。
您需要将新的数据源定义添加到 wildfly 配置(standalone.xml 或 domain.xml,具体取决于您的设置),或者在应用程序中以名为 <something>-ds.xml 的文件形式提供数据源定义。位于WEB-INF文件夹。在这两种情况下,您都需要正确设置 MSSQL 驱动程序(部署到模块,添加 module.xml 并将驱动程序定义添加到 widlfly config/subsytem=datasources)。这些操作也可以通过 jboss-cli 界面完成,以避免手动编辑配置文件。之后,从 persistence.xml 中删除连接属性,并使用新创建的 DS 的 jndi 名称添加 jta/non-jta-data-source 元素。另外,请删除您的 mssql 模块的全局定义

此链接可能对您有用: Wildfly Hibernate + In app datasource definition
JBoss DB Driver+Data source definition via cli

希望有帮助。

关于java - org.h2.jdbc.JdbcSQLException : Schema "DBO" not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42997491/

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