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.
You can specify it by schema element while defining table for your entity. Else, you can use separate EntityManager pointing to respective schema & then use the same entity, as their structure is similar.
If an entity or class has collection of values for a particular variable, then we can map those values using any one of the collection interfaces available in java. Hibernate can persist instances of java. util. Map, java.
Java classes whose objects or instances will be stored in database tables are called persistent classes in Hibernate. Hibernate works best if these classes follow some simple rules, also known as the Plain Old Java Object (POJO) programming model.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With