Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda