Cannot use session$userLogin in AnnotatedAccessGroupDefinition

Hi,
I’m trying to implement multi-tenant logic using accessConstraints based on createdBy attribute and session$userLogin, as such:

@JpqlConstraint(target = MyEntity.class, where = "{E}.createdBy = session$userLogin")
    @Override
    public ConstraintsContainer accessConstraints() {
        return super.accessConstraints();
    }

I got this error at runtime:

Exception Description: Problem compiling [select e from app_MyEntity e where e.createdBy = session$userLogin]. 
[38, 49] The basic mapping 'e.createdBy' cannot be used in conjunction with the = operator.
[52, 69] The identification variable 'session$userLogin' is not defined in the FROM clause.

Can’t see what’s wrong, or if this use case is not supported

Hi,

You have to put a „:“ before session like this - :session$userLogin

Cheers
Mario

Thank you Mario. Indeed it makes sense, since this is how you define substitutions in JPQL. Maybe a mention in the documentation could make it clearer though: Constraints - CUBA Platform. Developer’s Manual