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)database.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 Class
@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。当我试图从表StdUserV.java中获取数据时,我收到以下错误 -
org.hibernate.exception.GenericJDBCException: ERROR: cross-database references are not implemented: "gsw.public.std_users_v"
我已经google了一下,找到了我需要从 gsw.public .std_users_v(即目录)中删除粗体文本的解决方案,但我无法理解我该怎么做。属性“hibernate.default_catalog.null”是针对这个问题的一个努力。对于这种“交叉引用”问题,我也欢迎其他解决方案。 请帮忙。
答案 0 :(得分:1)
更改后找到解决方案 -
@Table(name = "std_users_v", catalog = "GSW", schema = "public")
到 -
@Table(name = "std_users_v")
答案 1 :(得分:0)
我使用Postgres的Spring Boot遇到了同样的问题。我发现你只需要删除Table.catalog属性。如果你的Postgres数据库中有多个模式,那么我建议你保留模式属性。
这会导致查询使用模式作为前缀,如:
Hibernate:从public.std_users_v中选择count(*)作为col_0_0_
如果您不删除目录属性,则最终会:
Hibernate:从GSW.public.std_users_v中选择count(*)作为col_0_0_
错误:未实现跨数据库引用:&#34; GSW.public.std_users_v&#34;