I don't quite understand the difference between a lazy and an extra-lazy fetch?
lazy -> the whole collection is selected when is accessed
extra-lazy -> one select per element, it's accessing fetching collection element by element (this is envers case)
I apologize for not making myself clear.
I was referring to "lazy collection fetching" and "extra lazy collection fetching" in section 19.1 from this below page.
After looking deep into code I narrowed down the issue to syntax of HQL generated by envers.
Suppose I have an entity Person having 5 records, then the loading varies based on the syntax of HQL and org.hibernate.Query API.
- session.createQuery("from Person p").list() --> results in 1 query.
- session.createQuery("from Person p").iterate() --> results in 6 queries.
- session.createQuery("select p from Person p").list() --> results in 1 query.
- session.createQuery("select new list(p) from Person p").list() --> results in 6 queries.
Envers is using option #4.
Option #3 and Option #4 have both its own advantages and disadvantages.
It would be great if this can be made as an configurable option either at class or at global level.
Heh, always something new about Hibernate .
Does the extra-lazy fetching happen only when retrieving an object using a query, or also when retrieving it using find(Class, Number)?
Anyway, this certainly needs to be fixed. Must have gotten broken when changing other things (I'm sure that relations where retrieved using 1 query when I originally wrote it). And it's a pretty hard thing to unit-test - maybe with hibernate statistics?
Please file a JIRA and if you would be willing to try and approach the problem to create a patch, it would be great.
Thanks for response.
One thing that I want to mention is extra-lazy fetching option is also varying on the database.
For H2 database "lazy collection fetching" is used whereas for MySql "extra lazy collection fetching" is used.
This makes it much harder to test, if unit tests cannot be run on an in-memory database.
Regarding find(Class, Number), to my knowledge it can only used to be fetch a single entity but not a collection.
Am I missing something here?
I will file a JIRA for this.
I am trying to modify the code for fixing this issue but might need some help.
Ah, I tested mainly on H2, hence I didn't notice the problems.
You're right that find() really uses a query internally, so that was a stupid question . Nevermind.
If you need any help ping me