How to identify a post database database with hibernet?

0

Good afternoon,

I have the following problem I need to send an email to a specific user within my database, that user is in a specific scheme different from the pubic scheme.

How can I identify the scheme that the user belongs to?

Currently within my code is the following:

     package framework.hibernate;
     import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
     public class SchemaResolver implements CurrentTenantIdentifierResolver 
      {
      private static String tenantIdentifier = "public";

     @Override
     public String resolveCurrentTenantIdentifier() {
     return tenantIdentifier;
     }

     @Override
     public boolean validateExistingCurrentSessions() {
        return false;
     }

      public void setTenantIdentifier(String tenantIdentifier) {
       SchemaResolver.tenantIdentifier = tenantIdentifier;
     }
   }

Inside my Java controller it looks like this:

       User user = userDAO.findOneByUsername(username);
        if(user != null){
         código
         }

In this case the user variable is filled in as null.

Thank you, sorry if the question is not understood.

    
asked by Carmen A. 18.12.2017 в 23:35
source

1 answer

0

From the java code I did not understand anything; What I understood from your description of what you have in the base: you have several schemes, each scheme contains the same tables and each scheme belongs to a different user. Correct me if I'm wrong.

First let's clarify something, in postgres the users are global objects. That is, they are not "inside" a base or a schema; they are above those objects.

Now, if you created the schemas using a command like: "CREATE SCHEMA AUTHORIZATION user" the schema was created with the same user name so it would be easy to locate the schema, if you used a command like "CREATE SCHEMA schema_name AUTHORIZATION user" the user would be the owner of the schema and you could locate it by executing this query: "select nspname from pg_namespace where nspowner = 'user' :: regrole".

Or you can clarify your question a bit more if I could not understand what you were asking.

    
answered by 19.12.2017 в 05:01