QueryHints for Unconstrained DB-Access

Hi,
I am trying to use JmixDataRepositories. I now need to do an unconstrained request.
In the documentation I find:
@QueryHints(@QueryHint(name = PersistenceHints.CACHEABLE, value = “true”))
but no hint for unconstrained access (like io.jmix.core.QueryHints.UNCONSTRAINED).
What name do I have to use? Is it available?

Thx.

Hi Mark,

You don’t need @QueryHints for this — there’s a dedicated annotation @ApplyConstraints specifically for controlling row-level security in data repositories.

Recommended approach: @ApplyConstraints

When set to false, the repository will use UnconstrainedDataManager under the hood. You can apply it to the entire interface or to specific methods only:

// entire repository — all methods bypass constraints
@ApplyConstraints(false)
public interface OrderRepository extends JmixDataRepository<Order, UUID> {
    List<Order> findByStatus(String status);
    List<Order> findByCustomer(Customer customer);
}
// mixed — per-method control
public interface OrderRepository extends JmixDataRepository<Order, UUID> {

    // regular DataManager, constraints applied
    List<Order> findByStatus(String status);

    // UnconstrainedDataManager, no constraints
    @ApplyConstraints(false)
    List<Order> findByCustomer(Customer customer);
}

More details in the documentation: Data Repositories :: Jmix Documentation


Alternative: inject UnconstrainedDataManager directly

If you prefer not to use repositories, or need to decide dynamically at runtime whether to apply constraints, you can inject UnconstrainedDataManager directly into a Spring bean or view controller:

@Autowired
private UnconstrainedDataManager unconstrainedDataManager;

public List<Order> loadAll() {
    return unconstrainedDataManager.load(Order.class)
            .list();
}

This is essentially what @ApplyConstraints(false) does under the hood, but with this approach you get full flexibility — for example, choosing between DataManager and UnconstrainedDataManager based on runtime conditions.


Thank you, thats perfect.

(I do want the Interface version)

1 Like