Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:46:27+00:00 2026-06-07T11:46:27+00:00

In my application I have Roles which have Permissions, I used to do this:

  • 0

In my application I have Roles which have Permissions, I used to do this:

   Query query =
        em.createQuery(
            "SELECT distinct r FROM Role r left join fetch r.permissions "
            + "where r.domain = ? " + "order by r.createdOn ").setParameter(
            1, domain);

    return query.getResultList();

But wanted finer control over lazy initializations. So I am trying this but it is not working because the join is executing as if it was an inner join, not bringing one role and its permissions but one result per row and per permission too.

public List<Role> findAll()
{
    CriteriaBuilder criteriaBuilder;
    CriteriaQuery<Role> criteriaQuery;
    Root<Role> queryRoot;
    Order createdOnDesc;
    TypedQuery<Role> typedQuery;
    List<Role> roleResultList;

    //initialize query system
    criteriaBuilder = em.getCriteriaBuilder();

    //select * from Role
    criteriaQuery = criteriaBuilder.createQuery(Role.class);
    queryRoot = criteriaQuery.from(Role.class);

    //join permissions by default "LEFT"
    //***THIS LINE IS FAILING*** ????
    queryRoot.join(Role_.permissions);

    //get query
    typedQuery = em.createQuery(criteriaQuery);

    //the steps below must be done to avoid lazy initialization exceptions
    //in case we want to access the list at a later time
    roleResultList = typedQuery.getResultList();

    for (Role role : roleResultList)
    {
        role.getPermissionsList();
    }

    return roleResultList;
}

Any thoughts or ideas will be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:46:29+00:00Added an answer on June 7, 2026 at 11:46 am

    It is little bit unclear to me what you want to achieve, but maybe following helps anyway.

    This is by default inner join, as told also in API.

    //join permissions by default "LEFT"
    //***THIS LINE IS FAILING*** ????
    queryRoot.join(Role_.permissions);
    

    If you need something similar to original JPQL query, that can be done with fetch. If you want to use left (outer) join instead, that can be done with join method that takes JoinType as argument:

    queryRoot.join(Role_.permissions, JoinType.LEFT);
    

    When distinct results are needed, then CriteriaQuery.distinct is useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application we have implemented role-based forms authentication. This has been handled using
I have an application which users Windows authentication in conjuction with ASPnet roles, so
I currently have a Web Application which is using it's own Permissions table which
In SQL Server you are able to have application role security, through which you
I have a database which has an application role. The role members all belong
I have some iptables rules which redirect requests for port 80 onto our application
I see an application have used Log.info = some info where are these logs
In my console application have an abstract Factory class Listener which contains code for
My Application has 3 activities (MainActivity,SampleActivity,TempActivity) and Application have to start from MainActivity because
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.