Note that there are some explanatory texts on larger screens.

plurals
  1. POGORM createCriteria and list do not return the same results : what can I do?
    primarykey
    data
    text
    <p>I am using <a href="http://www.grails.org/plugin/nimble" rel="noreferrer">Nimble</a> and <a href="http://www.grails.org/plugin/shiro" rel="noreferrer">Shiro</a> for my security frameworks and I've just come accross a GORM bug. Indeed :</p> <pre><code>User.createCriteria().list { maxResults 10 } </code></pre> <p>returns <strong>10 users</strong> whereas <code>User.list(max: 10)</code> returns <strong>9 users</strong> ! </p> <p>After further investigations, I found out that <code>createCriteria</code> <strong>returns twice the same user</strong> (admin) <strong>because admin has 2 roles</strong>!!! (I am not joking).</p> <p>It appears that any user with more than 1 role will be returned twice in the <code>createCriteria</code> call and <code>User.list</code> will return <code>max-1</code> instances (i.e 9 users instead of 10 users) </p> <p><strong>What workaround can I use in order to have 10 unique users returned ?</strong></p> <p>This is a very annoying because I have no way to use pagination correctly. </p> <hr> <p>My domain classes are:</p> <pre><code>class UserBase { String username static belongsTo = [Role, Group] static hasMany = [roles: Role, groups: Group] static fetchMode = [roles: 'eager', groups: 'eager'] static mapping = { roles cache: true, cascade: 'none', cache usage: 'read-write', include: 'all' } } class User extends UserBase { static mapping = {cache: 'read-write'} } class Role { static hasMany = [users: UserBase, groups: Group] static belongsTo = [Group] static mapping = { cache usage: 'read-write', include: 'all' users cache: true groups cache: true } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload