Home Fully qualify Oracle table name in Hibernate
Reply: 1

Fully qualify Oracle table name in Hibernate

Mr.H.
1#
Mr.H. Published in 2018-01-11 16:17:45Z

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:

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

@Entity
@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?

Simon Martinelli
2#
Simon Martinelli Reply to 2018-01-11 16:36:17Z

With Oracle you have to use the schema attribute:

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

@Entity
@Table(name = "MyModel2", schema= "DB2")
public class MyModel2 {...}
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO