views:

113

answers:

1

There is a typical situation being faced where different tables are scattered through different schemas in Oracle database and they are related to each other (encompassing all different types of relations).

How can they be represented in Hibernate using annotations as when a sessionfactory handle is created for one schema, tables in that schema can't access other related tables (foreign key relation to tables in other schema)?

For a query like following, exception is thrown -

"from table1 as model where model.table2Name.table2column = "+foo

Exception comes as -

org.hibernate.QueryException: 
    could not resolve property: 
    table2column of: 
    com.test.table1 
    [from com.test.table1 as model where model.table2Name.table2column = 1]

Here table1 and table2 are present in different schemas.

A: 

Finally I got the solution. It is done using the schema annotation for that table as follows - @Entity @Table(name = "table1", schema="schema1") Also the mapping of table2 class should be included in configuration file of table1 schema.

nitesh