loyalflow
loyalflow

Reputation: 14879

How can I switch postgres schema's on a per query basis with Hiberante?

Is it possible for me to set the schema dynamically with Hibernate?

On the same web page (session), I want the ability to alter the schema potentially per query I make.

Is this possible?

i.e. on each DAO method I will pass the name of the schema to connect to.

Upvotes: 0

Views: 1151

Answers (1)

Denis de Bernardy
Denis de Bernardy

Reputation: 78443

You can set the search path, e.g.:

SET search_path TO 'schemaname,public'

If you just need this for a single query, you can do that in two ways:

  1. Run two queries, one to set the search_path and the other for your actual query. If you do this, don't forget to do this in subsequent queries, as they'll be affected too).

  2. Change your query so it selects from schemaname.tablename rather than plain tablename.

Upvotes: 1

Related Questions