Reputation: 958
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...
I am using Postgresql. While i am trying to fetch data from Table StdUserV.java i am getting the following error-
org.hibernate.exception.GenericJDBCException: ERROR: cross-database references are not implemented: "gsw.public.std_users_v"
I have googled around and found the solution that i need to remove bolded text from gsw.public.std_users_v (i.e. catalog) but i am not getting how can i do it. The property "hibernate.default_catalog.null" was one effort towards this issue. I welcome the other solutions too for this "cross-reference" problem. Please help.
Upvotes: 0
Views: 1443
Reputation: 768
I had the same problem with Spring Boot using Postgres. I figured out that you only have to remove the Table.catalog attribute. In case you have multiple schemas in your Postgres database then I advise you to leave the schema attribute.
This results in the query using the schema as a prefix like:
Hibernate: select count(*) as col_0_0_ from public.std_users_v
If you don't remove the catalog attribute it ends up in:
Hibernate: select count(*) as col_0_0_ from GSW.public.std_users_v
ERROR: cross-database references are not implemented: "GSW.public.std_users_v"
Upvotes: 0
Reputation: 958
found solution after changing-
@Table(name = "std_users_v", catalog = "GSW", schema = "public")
to-
@Table(name = "std_users_v")
Upvotes: 1