History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-555
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Graeme Rocher
Reporter: Paul Barry
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Grails

many-to-many relationships are initialized when they shouldn't be

Created: 04/Jan/07 07:47 AM   Updated: 19/Jan/07 04:39 AM
Component/s: Persistence
Affects Version/s: 0.3.1
Fix Version/s: 0.4

Time Tracking:
Not Specified


 Description  « Hide
I've got an app that I'm working on that has a few different
many-to-many collections. There are a couple hundred rows in each of
the tables. When I do a simple "Article.get(1)" in my grails console,
it takes 5 - 10 seconds to return. I turned on the hibernate debug
logging and you can see tons of statements being executed just to
return that one entity.

From looking at the statements, it appears the relationships are lazy,
but grails tries to initialize all of those relationships, even if I'm
not using them. To track down the problem, I created a simple test
app with a Foo and and a Bar object with a many-to-many relationship
between them. I created 1 Foo and 1 Bar and related the Bar to the
Foo. Then, if I execute Foo.get(1) in the grails console, I see these
SQL statements:

select foo0_.id as id0_0_, foo0_.version as version0_0_, foo0_.name as
name0_0_ from foo foo0_ where foo0_.id=?

select bars0_.bars_id as bars1_0_, bars0_.foos_id as foos2_0_ from
foo_bar bars0_ where bars0_.bars_id=?

select bar0_.id as id2_0_, bar0_.version as version2_0_, bar0_.name as
name2_0_ from bar bar0_ where bar0_.id=?

select foos0_.foos_id as foos2_0_, foos0_.bars_id as bars1_0_ from
foo_bar foos0_ where foos0_.foos_id=?

I would expect only the first statement, but based on the other
statements it appears that grails it trying to initialize all lazy
relationships, even though they are not need for my simple statement.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.