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

时间:2016-07-11 14:18:39

标签: hibernate jpa wildfly-8 postgresql-9.4 hbm2ddl

我正在尝试使用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;

这是我的persistence.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会分析我的persistence.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]

有趣的是,我可以使用persistence.xml中提供的凭据通过pgadmin3成功登录到我的PostgreSQL服务器上。此外,我可以访问名为“my-schema”的模式。

因此,配置出现问题。为什么Hibernate无法找到架构?

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

更新:抱歉,原帖中有拼写错误!它不是“my-project.users_permissions”,而是“my-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]

1 个答案:

答案 0 :(得分:0)

您可以访问&#34; my-schema&#34;,但此处的堆栈跟踪表示一个名为&#34; my-project&#34;的架构。我要检查以确保存在。

[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