Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
Spring Data JPA global filter clause which inherits for all repository methods

We are developing a multi tenancy web application using Spring boot + Spring data JPA with hibernate.

Multi tenancy is achieved by having an Organization table, which is wired to almost every table as a foreign key. Which means every DB call (Spring Data repository query methods) will have to be checked with the organization id.

I need a way that, this "where organization_id = ?" check to be injected automatically for every query method. So that developers won't have to specifically bother about organization id checks.

Is this achievable from Spring Data JPA framework? What are the pros, cons of this approach?

Thanks for your time.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If your have a base class, say BaseEntity you can use @org.hibernate.annotations.Filter:

  1. In BaseEntity:

    @FilterDef(name = "organizationFilter", parameters = @ParamDef( name="orgId", type="long" )) @Filter(name = "organizationFilter", condition = "lang_id=:orgId")

  2. On initialization of a session (override JpaTransactionManager.createEntityManagerForTransaction()?):

    session.enableFilter("organizationFilter").setParameter("orgId", organization.getId());

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda