Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;“缺少表格”;论物化视图_Java_Hibernate_Postgresql_Jpa_Materialized Views - Fatal编程技术网

Java &引用;“缺少表格”;论物化视图

Java &引用;“缺少表格”;论物化视图,java,hibernate,postgresql,jpa,materialized-views,Java,Hibernate,Postgresql,Jpa,Materialized Views,我拥有以下实体: @Entity @Table(name = "full_address") public class FullAddress { @Id @Column(name = "guid") private String id; @Column(name = "address") private String address; //getters and setters omitted } 我还创建了物化视图,如下所示: CREATE TABLE add

我拥有以下实体:

@Entity
@Table(name = "full_address")
public class FullAddress {

  @Id
  @Column(name = "guid")
  private String id;

  @Column(name = "address")
  private String address;

  //getters and setters omitted
}
我还创建了物化视图,如下所示:

CREATE TABLE address_table (
  -- address fields,
  aoid VARCHAR(36),
  CONSTRAINT address_pk PRIMARY KEY (aoid)
);
CREATE MATERIALIZED VIEW full_address AS
  SELECT buildFullAddressById(addrobj.aoid) AS address, addrobj.aoid AS guid FROM address_table AS addrobj;

-- buildFullAddressById is an sql function which is not important here
当我启动Tomcat应用程序时,我总是

org.hibernate.hibernateeexception:缺少表:完整地址

为什么会这样?如何修复它


UPD:看起来像hibernate中的一个bug:

这肯定是hibernate中的一个bug,在这里描述:


因此,我建议删除
hibernate.hbm2ddl.auto
属性作为解决办法。

这肯定是hibernate的一个bug,下面介绍了它:


因此,我建议删除
hibernate.hbm2ddl.auto
属性作为一种解决方法。

我在过去几天中都遇到了相同的错误。如前所述,可以在
persistence.xml
中禁用
hibernate.hbm2ddl.auto
属性,但如果您的项目正在快速开发,这不是一个好主意

TL;DR:将属性
hibernate.hbm2dll.extra\u physical\u table\u类型设置为
物化视图

或者将
-Dhibernate.hbm2dll.extra_physical_table_types=“物化视图”
添加到VM选项中。但最好将这些选项添加到配置文件中


现在,我们正在使用PostgreSQL 9.6和Hibernate 5.2.12.Final。为什么所有物化视图验证都失败,出现以下异常:

原因:org.hibernate.tool.schema.spi.SchemaManagementException: 架构验证:缺少表[我们的\u项目\u Schema.mv\u一个\u视图]

成功通过验证的所有实体都是简单表或视图

这似乎是通用数据库的默认行为。在第
79-81行的源中,它们仅添加以下类型:

final List<String> tableTypesList = new ArrayList<>();
tableTypesList.add( "TABLE" );
tableTypesList.add( "VIEW" );
在线
56
上声明
私有字符串[]extraPhysicalTableTypes,,
在
71-77行
中,此数组中添加了更多值:

if ( !"".equals( extraPhysycalTableTypesConfig.trim() ) ) {
    this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
        ",;",
        extraPhysycalTableTypesConfig,
        false
    );
}
它们来自行
66-70
,在键
EXTRA_PHYSICAL_TABLE_TYPES
下编码为字符串,默认值为空:

final String extraPhysycalTableTypesConfig = configService.getSetting(
    AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES,
    StandardConverters.STRING,
    ""
);
而在线
1545
是该键的声明:

/**
 * Identifies a comma-separate list of values to specify extra table types,
 * other than the default "TABLE" value, to recognize as defining a physical table
 * by schema update, creation and validation.
 *
 * @since 5.0
 */
String EXTRA_PHYSICAL_TABLE_TYPES = "hibernate.hbm2dll.extra_physical_table_types";
因此,添加此属性将向
tableTypesList
添加另一个条目,该条目用于筛选数据库中的许多其他实体,例如序列、索引、临时表和其他可能具有类似于物化视图名称的实体

如果您感兴趣,我的
persistence.xml
就是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
    <persistence-unit name="project-pu">
        <jta-data-source>java:jboss/datasources/project-pu</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.hbm2dll.extra_physical_table_types" value="MATERIALIZED VIEW"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="false"/>
            <property name="hibernate.use_sql_comments" value="false"/>
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/mgt"/>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
        </properties>
    </persistence-unit>
</persistence>

java:jboss/datasources/projectpu

我知道这是一个很老的帖子,但我和这个问题斗争了几天。我没有找到答案,所以我决定把它放在互联网上的某个地方。这个地方变成了这里

在过去的几天里,我都有同样的问题。如前所述,可以在
persistence.xml
中禁用
hibernate.hbm2ddl.auto
属性,但如果您的项目正在快速开发,这不是一个好主意

TL;DR:将属性
hibernate.hbm2dll.extra\u physical\u table\u类型设置为
物化视图

或者将
-Dhibernate.hbm2dll.extra_physical_table_types=“物化视图”
添加到VM选项中。但最好将这些选项添加到配置文件中


现在,我们正在使用PostgreSQL 9.6和Hibernate 5.2.12.Final。为什么所有物化视图验证都失败,出现以下异常:

原因:org.hibernate.tool.schema.spi.SchemaManagementException: 架构验证:缺少表[我们的\u项目\u Schema.mv\u一个\u视图]

成功通过验证的所有实体都是简单表或视图

这似乎是通用数据库的默认行为。在第
79-81行的源中,它们仅添加以下类型:

final List<String> tableTypesList = new ArrayList<>();
tableTypesList.add( "TABLE" );
tableTypesList.add( "VIEW" );
在线
56
上声明
私有字符串[]extraPhysicalTableTypes,,
在
71-77行
中,此数组中添加了更多值:

if ( !"".equals( extraPhysycalTableTypesConfig.trim() ) ) {
    this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
        ",;",
        extraPhysycalTableTypesConfig,
        false
    );
}
它们来自行
66-70
,在键
EXTRA_PHYSICAL_TABLE_TYPES
下编码为字符串,默认值为空:

final String extraPhysycalTableTypesConfig = configService.getSetting(
    AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES,
    StandardConverters.STRING,
    ""
);
而在线
1545
是该键的声明:

/**
 * Identifies a comma-separate list of values to specify extra table types,
 * other than the default "TABLE" value, to recognize as defining a physical table
 * by schema update, creation and validation.
 *
 * @since 5.0
 */
String EXTRA_PHYSICAL_TABLE_TYPES = "hibernate.hbm2dll.extra_physical_table_types";
因此,添加此属性将向
tableTypesList
添加另一个条目,该条目用于筛选数据库中的许多其他实体,例如序列、索引、临时表和其他可能具有类似于物化视图名称的实体

如果您感兴趣,我的
persistence.xml
就是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
    <persistence-unit name="project-pu">
        <jta-data-source>java:jboss/datasources/project-pu</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.hbm2dll.extra_physical_table_types" value="MATERIALIZED VIEW"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="false"/>
            <property name="hibernate.use_sql_comments" value="false"/>
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/mgt"/>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
        </properties>
    </persistence-unit>
</persistence>

java:jboss/datasources/projectpu

我知道这是一个很老的帖子,但我和这个问题斗争了几天。我没有找到答案,所以我决定把它放在互联网上的某个地方。这个地方变成了这里

我发现最简单的解决方案(假设您仍然希望使用Hibernate验证模式)是向表定义添加一个子选择

使用hbm.xml

<hibernate-mapping>
    <class name="com.initech.MvObject" table="MV_OBJ">
        <!-- This is necessary when using older Hibernate versions because of 
            Hibernate bugs. See
            https://hibernate.atlassian.net/browse/HHH-1329
            https://hibernate.atlassian.net/browse/HHH-9602
         -->
        <subselect>select * from MV_OBJ</subselect>

我发现最简单的解决方案(假设您仍然希望使用Hibernate验证模式)是向表定义添加一个子选择

使用hbm.xml

<hibernate-mapping>
    <class name="com.initech.MvObject" table="MV_OBJ">
        <!-- This is necessary when using older Hibernate versions because of 
            Hibernate bugs. See
            https://hibernate.atlassian.net/browse/HHH-1329
            https://hibernate.atlassian.net/browse/HHH-9602
         -->
        <subselect>select * from MV_OBJ</subselect>

你检查了你的授权许可了吗?你检查了你的授权许可了吗?你救了我!谢谢你,你救了我!非常感谢。