Home Fully qualify Oracle table name in Hibernate
Reply: 0

Fully qualify Oracle table name in Hibernate

user1238 Published in May 21, 2018, 11:19 am

My Setup: I am using Hibernate 5 with the Oracle JDBC driver oracle.jdbc.driver.OracleDriver and dialect org.hibernate.dialect.Oracle9iDialect.

My modelclasses look like this:

@Table(name = "MyModel1", catalog = "DB1")
public class MyModel1 {...}

@Table(name = "MyModel2", catalog = "DB2")
public class MyModel2 {...}

My Problem: I have multiple modelclasses that are spread about different DBs on the same DBserver. I have to use a single DB-connection to query all of my modelclasses so I connect to DB1 for querying. Everything would be fine, if Hibernate would generate SQL queries like

select * from DB1.MyModel1;

but it does not. For some reason it makes its queries without the catalog ie.

select * from MyModel1;

which is fine for MyModel1 because I connect to DB1 but I need a fully qualified query for MyModel2 otherwise it throws an exception, because the table of MyModel2 cannot be found in DB1.

Do you know any way to trick Hibernate or JPA or the dialect into building queries with fully qualified tablenames?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.393364 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO