Version 7.0 JPQL session parameter?

Version 6 allowed access to the user session in the datasource query

:session$userLogin

for example.

Would I be right in assuming this is not supported in the new data loaders?

Hello @ray1

It’s designed to not pass such parameters automatically. In case of containers you have to pass params manually:

Collection container with param:

<collection id="usersDc"
            class="com.haulmont.cuba.security.entity.User"
            view="_local">
    <loader id="usersDl">
        <query>
            <![CDATA[select e from sec$User e where e.login = :container$userLogin]]>
        </query>
    </loader>
</collection>

Pass param in controller:

@Inject
private CollectionLoader<User> usersDl;
@Inject
private UserSession userSession;

@Subscribe
private void onInit(InitEvent event) {
    String login = userSession.getUser().getLogin();

    usersDl.setParameter("container$userLogin", login);
    usersDl.load();
}

You can find more detailed example in our documentation: DeclarativeLoaderParameters mixin

Regards,
Daniil

Faced the same problem, IllegalStateException lack of query argument :session$userLogin. 7.1 docs in 3.6.2.2.2. Query Parameters says that :session$userLogin should be working, but it’s not… Maybe docs need to be updated…

The docs are probably fine. By the looks of it, you’re reading the section on the legacy data API. The new API doesn’t support the session parameters.