hbm2ddl 架构导出由于“未找到架构”XYZ“而失败



我正在尝试在使用Hibernate 4.3.11启动Wildfly 8.2.1期间将DDL导出到PostgreSQL 9.4数据库。

DDL 是使用 hibernate-maven-plugin (http://juplo.de/hibernate-maven-plugin/) 创建的,如下所示:

alter table users_permissions 
    drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j;
[more alter table...]
drop table permissions cascade;
[more drop table...]
create table permissions (
    user_ID int8 not null,
    permission varchar(64) not null,
    primary key (user_ID)
);
[more create table...]
alter table users 
    add constraint UK_ey6y24h3nkw1cvrryc9khsl5p  unique (user_name, email);
[more alter table...]
create sequence hibernate_sequence;

这是我的坚持.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
   <persistence-unit name="${persistence.unitName}" transaction-type="JTA">
      <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
      <class>
     net.my-project.publisher.entity.UserEntity
      </class>
  <class>
     net.my-project.publisher.entity.RoleEntity
  </class>
  <class>
     net.my-project.publisher.entity.PermissionEntity
  </class>
  <properties>
     <property name="hibernate.connection.driver_class"
               value="org.postgresql.Driver"/>
     <property name="hibernate.connection.url"
               value="jdbc:postgresql://localhost:5432/my-project"/>
     <property name="hibernate.connection.username"
               value="${postgresql.login}"/>
     <property name="hibernate.connection.password"
               value="${postgresql.password}"/>
     <property name="hibernate.default_schema"
               value="${persistence.unitName}"/>
     <property name="hibernate.dialect"
               value="org.hibernate.dialect.PostgreSQL9Dialect"/>
     <property name="hibernate.archive.autodetection"
               value="class"/>
     <property name="hibernate.hbm2ddl.auto"
               value="create"/>
     <property name="hibernate.max_fetch_depth"
               value="3"/>
     <property name="hibernate.show_sql"
               value="true"/>
     <property name="hibernate.format_sql"
               value="true"/>
     <property name="hibernate.order_updates"
               value="true"/>
     <property name="hibernate.generate_statistics"
               value="true"/>
     <property name="hibernate.use_sql_comments"
               value="true"/>
     <property name="hibernate.cache.use_query_cache"
               value="true"/>
     <property name="hibernate.cache.use_second_level_cache"
               value="true"/>
     <property name="hibernate.cache.provider_class"
               value="org.hibernate.cache.EhCacheProvider"/>
     <property name="hibernate.cache.region.factory_class"
               value="org.hibernate.cache.EhCacheRegionFactory"/>
     <property name="hibernate.cache.use_structured_entries"
               value="true"/>
     <property name="hibernate.transaction.auto_close_session"
               value="false"/>
     <property name="hibernate.connection.charSet"
               value="UTF-8"/>
  </properties>

现在,当部署到 WildFly 服务器时,Hibernate 会分析我的持久性.xml并尝试将 DDL 导出到我的 PostgreSQL 数据库。但是,这将失败:

[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010417: Started Driver service with driver-name = my-project.ear_org.postgresql.Driver_9_4
[org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016008: Starting weld service for deployment my-project.ear
[org.jboss.as.jpa] (ServerService Thread Pool -- 50) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'my-project.ear/persistence-0.1-SNAPSHOT.jar#my-project'
[org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 50) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 50) HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000227: Running hbm2ddl schema export
[stdout] (ServerService Thread Pool -- 50) Hibernate: 
[stdout] (ServerService Thread Pool -- 50)     alter table my-project.users_permissions 
[stdout] (ServerService Thread Pool -- 50)         drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j
[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: alter table my-project.users_permissions drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j
[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Schema "MY-SCHEMA" not found; SQL statement:
alter table my-schema.users_permissions 
    drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j [90079-173]
有趣的是

,我可以使用持久性.xml中给出的凭据通过pgadmin3成功登录到我的PostgreSQL服务器。此外,我可以访问一个名为"my-schema"的模式。

因此,配置一定有问题。为什么 Hibernate 找不到模式?

任何帮助都非常感谢。沃尔特

更新:对不起,我的原始帖子中有错字!这不是"我的project.users_permissions",而是"我的schema.users_permissions"。

[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: alter table my-schema.users_permissions drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j
[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Schema "MY-SCHEMA" not found; SQL statement:
alter table my-schema.users_permissions 
    drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j [90079-173]

您可以访问"my-schema",但此处的堆栈跟踪指示名为"my-project"的架构。我会检查以确保存在一个。

[stdout] (ServerService Thread Pool -- 50) Hibernate: 
[stdout] (ServerService Thread Pool -- 50)     alter table my-project.users_permissions 
[stdout] (ServerService Thread Pool -- 50)         drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j
[org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: alter table my-project.users_permissions drop constraint if exists FK_eije6ps36awul7w1e8w9x0k0j

最新更新