Grails - Weird behavior when using max param in domain list() method

I'm using spring-security-acl plugin and have User & Role defined as a many-to-many relationship. I also have a UserRole domain class.

I have 40 users in my DB.

If I do:

User.list()

I get all 40 users.

But I if I do something like:

User.list(offset: 0, max: 20)

I only get 12 users, when I should be getting 20. The use of the max param produces very weird behaviors for that domain.

I can't figure out what's happening. I guess it might have something to do with the many-to-many relationship.

Any help will be really appreciated.

Answers


I assume, the issue here is with one-to-many/many-to-many association. Your code is trying to fetch User and his Roles using join. This means when you try to fetch a User with three Roles, three rows are returned instead one. (This is SQL issue and you can do nothing about it)

So when you give 40 as the max, there are 40 rows returned by SQL, but that contains the duplicate rows. Now when Grails converts the the data into objects, it removes the duplicates, thus leaving you with 12 rows.

Solution : Remove eager fetching of Roles from User and try to fetch just the User objects.U


Need Your Help

rsync include files from specific folder?

linux backup rsync

I have a directory structure as follows

PowerShell get multiple elements from DOM

powershell powershell-v3.0

I am trying to grab multiple elements from a website, but when I put either both parameters inside one set of parenthesis separated by comma I get "Cannot find an overload for "getElementsByTagName...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.