【问题标题】:org.hibernate.exception.GenericJDBCException: ERROR: cross-database references are not implementedorg.hibernate.exception.GenericJDBCException:错误:未实现跨数据库引用
【发布时间】:2014-02-27 08:10:29
【问题描述】:

1) Dispatcher-Servlet

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${driverClassName}"/>
    <property name="url" value="${url}"/>
    <property name="username" value="${username}"/>
    <property name="password" value="${password}"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${dialect}</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.default_catalog.null"></prop>       
        </props>
    </property>
</bean>

2) 数据库.properties

driverClassName=org.postgresql.Driver
dialect=org.hibernate.dialect.PostgreSQLDialect
url=jdbc:postgresql://192.168.1.20:5432/GSW
username=postgres
password=postgres

3) Java 类

@Entity
@Table(name = "std_users_v", catalog = "GSW", schema = "public")
@NamedQueries({
@NamedQuery(name = "StdUsersV.findAll", query = "SELECT s FROM StdUsersV s")})
public class StdUsersV implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
private Integer id;
@Column(name = "user_group_id")
private BigInteger userGroupId;
@Size(max = 50)
@Column(name = "user_name", length = 50)
private String userName;
@Size(max = 100)
@Column(name = "password", length = 100)
private String password;
@Column(name = "org_unit_id")
private BigInteger orgUnitId;
@Column(name = "active_flag")
private Boolean activeFlag;
@Column(name = "start_date")
@Temporal(TemporalType.TIMESTAMP)
private Date startDate;
@Column(name = "end_date")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;
@Column(name = "created_by")
private BigInteger createdBy;
@Column(name = "creation_date")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@Column(name = "updated_by")
private BigInteger updatedBy;
@Column(name = "update_date")
@Temporal(TemporalType.TIMESTAMP)
private Date updateDate;
@Size(max = 20)
@Column(name = "user_group_name", length = 20)
private String userGroupName;
getters and setters...

我正在使用 Postgresql。当我尝试从 Table StdUserV.java 中获取数据时,我收到以下错误-

org.hibernate.exception.GenericJDBCException: ERROR: cross-database references are not     implemented: "gsw.public.std_users_v"

我用谷歌搜索并找到了我需要从 gsw.public.std_users_v(即目录)中删除粗体文本的解决方案,但我不知道该怎么做。属性“hibernate.default_catalog.null”是解决此问题的一项努力。对于这个“交叉引用”问题,我也欢迎其他解决方案。 请帮忙。

【问题讨论】:

  • 请显示您的 java 类、映射以及如何执行查询。
  • 请找到更新的Java类

标签: spring hibernate postgresql spring-mvc


【解决方案1】:

更改后找到解决方案-

@Table(name = "std_users_v", catalog = "GSW", schema = "public")

到-

@Table(name = "std_users_v")

【讨论】:

    【解决方案2】:

    我在使用 Postgres 的 Spring Boot 中遇到了同样的问题。我发现您只需要删除 Table.catalog 属性。如果您的 Postgres 数据库中有多个模式,那么我建议您保留模式属性。

    这会导致查询使用架构作为前缀,例如:

    休眠:从 public.std_users_v 中选择 count(*) as col_0_0_

    如果您不删除目录属性,它最终会出现:

    休眠:从 GSW.public.std_users_v 中选择 count(*) 作为 col_0_0_

    错误:未实现跨数据库引用:“GSW.public.std_users_v”

    【讨论】:

      猜你喜欢
      • 2019-01-17
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 2014-06-09
      相关资源
      最近更新 更多