Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting hibernate default schema name programmatically from session factory?

I was wondering if there is a way to get the default schema name from session factory, somehow? The reason I need to get it is because I have to use a one native SQL and I have multiple session factories for multiple schemas and a single data source. All the generated hibernate queries are being ran by a single user which has select access to other schemas.

like image 413
John Avatar asked Jan 28 '11 20:01

John


People also ask

What is hibernate default schema?

The default schema applies to all tables mapped by your entities. I was wondering if I can use any similar hibernate property for Dbtest which can use a different schema( mock_schema1 ) instead of the default schema( schema1 ).

How to get Hibernate Session in java?

Create a new Criteria instance, for the given entity class, or a superclass of an entity class. Create a new Criteria instance, for the given entity name. Return the identifier value of the given entity as associated with this session. Create a new instance of Query for the given collection and filter string.


1 Answers

I just found out that hibernate has {h-schema} replacement that can be used in native sql queries. So this does the job cleanly when you are connected to a one schema in oracle database and want to execute queries against different schemas. Example would be:

select * from {h-schema}table_name

This ways instead of doing a manual replaceAll in a query, hibernate will take care of everything given that each session factory is configured with "hibernate.default_schema" property.

like image 113
John Avatar answered Sep 18 '22 08:09

John