Search code examples
hibernatespring-roo

Spring Roo Hiberanate makes extra SELECT * before SELECT with limit and offset


Using all spring roo vanilla controllers and objects, every time I make request for e.g. /project/something?page=N&size=M, hibernate log shows three requests, first there is SELECT which fetches ALL entries, and then there is one with LIMIT and OFFSET, followed by SELECT count.

Why is there this first select that fetches all entries? I want to get rid of this one because it hogs performance really bad in case there are many entries in table.

Is it hibernate or spring roo related?

I'm using latest roo & hibernate.


Solution

  • Ok, I have found it!

    Roo 1.1.5 calls populate methods on every CRUD request even before actual controller method is called. Populate methods fetches all entries from db, which makes it a huge overload, huge enough to make web app quite unusable and look bad in front of your managers :(

    What you can do is implement populate methods yourself and make them do something other than fetch all bloody entries (use with caution, you might cripple other stuff, watch for create/update), e.g. return null or something like that.

    This is also reported as a bug and Spring Jira, seemingly fixed with Roo 1.2.0, so better solution is to upgrade.