0 Replies Latest reply on Apr 27, 2009 11:05 AM by Chris Rose

    Using a SessionFactory with multiple connection contexts

    Chris Rose Newbie

      I would like to describe a use case for Hibernate, and get some feedback as to
      whether it's possible as described, or whether I need to consider a different
      approach.

      Our application operates in multiple instances of the same database schema for
      purposes of isolation, as well as a second schema that is global to all
      participators. A single user is granted access to parts of all of these
      schemas to perform operations that must take effect on all of them.

      So, we have this arrangement:

      SchemaA: r/w accessible to UserA, r/o accessible to UsersB[0..N]
      SchemaB[0..N]: r/w accessible to UsersB[0..N]

      UserC with access to A, B[0..N]

      This arrangement is a business requirement, so I can't really change it.

      Additionally, the names of the UserB class users are not known at configuration
      or compilation time, they are provided at runtime by data, and new ones may be
      created at any time without an application restart; the schema is instantiated
      by an external process.

      So, we have two scenarios:

      1. Logged in as UserB[m]. Accesses to tables within SchemaB do not need schema
      qualification, acceses to SchemaA require qualification as UserA.TABLE.

      2. Logged in as UserC. All accesses require schema name qualification,
      and the specific instance of UserB that must be used is determined from
      current state.

      Is there any way whatsoever to configure a single SessionFactory to do this?
      I know that I can create a separate SessionFactory for each UserB and for
      UserC, but that makes for a very expensive delay the first time a
      SessionFactory is initialized. The thing here is that each instance of SchemaB
      is identical. It seems like a waste to configure a separate SessionFactory
      for each of them.

      Any advice on how to do this would be welcome. If it makes a difference, this
      is a J2SE application.