Skip to content

OBGM-559 Error message when open add items to invoice dialog (fix after QA)#4140

Merged
awalkowiak merged 1 commit intofeature/upgrade-to-grails-3.3.10from
OBGM-559-fix
Jul 10, 2023
Merged

OBGM-559 Error message when open add items to invoice dialog (fix after QA)#4140
awalkowiak merged 1 commit intofeature/upgrade-to-grails-3.3.10from
OBGM-559-fix

Conversation

@alannadolny
Copy link
Collaborator

No description provided.

@alannadolny alannadolny self-assigned this Jul 6, 2023
region:
factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
use_query_cache: true
use_query_cache: false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this setting, not refreshed SQL views results were used.
For example: When I opened add items modal on the invoice workflow and I add one item with its maximum available quantity and I open this modal a second time, the createCriteria is looking for items that are currently added to the invoice and were deleted from invoice_item_candidate view.
It was causing this error: No row with the given identifier exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alannadolny Interesting. I was seeing those "No row with the given identifier exists" errors at some point as well but had no idea what was causing them.

During your research did you find any articles or documentation that would help explain this? If so, please add what you've discovered to the ticket.

https://gorm.grails.org/6.0.x/hibernate/manual/#_caching_queries

I'm fine with disabling the query cache if that makes the most sense and is considered best practice.

However, I'm skeptical that the problem we're facing is solely due to the use_query_cache setting itself. My skepticism comes from the fact that the behavior should be considered a critical bug. So if this is what the query cache was intended to do, then no one would use it and it would be burned with fire. I haven't done much research on this yet, but I'm guessing this might have more to do with our lack of equals and hashCode for most domain classes. See https://pihemr.atlassian.net/browse/OBGM-341.

Some resources to review
https://blog.nareshak.com/effective-java-with-groovy-are-you-implementing-equals-and-hashcode-correctly/
https://stackoverflow.com/questions/29683592/should-i-implement-equals-and-hashcode-in-a-domain-class

So while we can turn this feature off for now, we should create a new spike ticket to research the actual problem in more depth, as well as gain a better understanding of the Hibernate Query Cache.

As part of that ticket please also provide some details on the different Hibernate cache settings. For example, what's the difference between these two settings

hibernate.cache.queries
hibernate.cache.use_query_cache

On top of the links provided above, my cursory search provided some very old results. I'm not sure if these are still relevant but they gave me a better understanding of what might be happening.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmiranda as Alan is out today, I'll answer, because I advised Alan to set this property to false globally.
Alan discovered, that the view data is not refreshed and adding this:

cache(false)

to the createCriteria caused the query to be working fine.
What came immediately to my mind was this hibernate setting, as not a long time ago I was digging into that and read a bit about it. Setting this to false fixed the issue and we were scared that this could be a big bug going forward, we disabled this for now globally.

I know we'd expect that the caching should be enabled explicitly (it shouldn't be enabled by default in this case for createCriteria), but I think the reason for that might be how mapping in InvoiceItemCandidate is defined (3rd line):

static mapping = {
    id generator: 'uuid'
    version false
    cache usage: "read-only"
}

so maybe Hibernate/Grails automatically for domains defined like that, enables the caching (to be figured out).

I agree we should have a spike ticket regarding this caching (and I believe you made a comment in my hibernate document about that, to create the ticket).
For now this LGTM.

cc @alannadolny @awalkowiak @drodzewicz

Copy link
Member

@jmiranda jmiranda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but please read my comment before merging.

region:
factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
use_query_cache: true
use_query_cache: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alannadolny Interesting. I was seeing those "No row with the given identifier exists" errors at some point as well but had no idea what was causing them.

During your research did you find any articles or documentation that would help explain this? If so, please add what you've discovered to the ticket.

https://gorm.grails.org/6.0.x/hibernate/manual/#_caching_queries

I'm fine with disabling the query cache if that makes the most sense and is considered best practice.

However, I'm skeptical that the problem we're facing is solely due to the use_query_cache setting itself. My skepticism comes from the fact that the behavior should be considered a critical bug. So if this is what the query cache was intended to do, then no one would use it and it would be burned with fire. I haven't done much research on this yet, but I'm guessing this might have more to do with our lack of equals and hashCode for most domain classes. See https://pihemr.atlassian.net/browse/OBGM-341.

Some resources to review
https://blog.nareshak.com/effective-java-with-groovy-are-you-implementing-equals-and-hashcode-correctly/
https://stackoverflow.com/questions/29683592/should-i-implement-equals-and-hashcode-in-a-domain-class

So while we can turn this feature off for now, we should create a new spike ticket to research the actual problem in more depth, as well as gain a better understanding of the Hibernate Query Cache.

As part of that ticket please also provide some details on the different Hibernate cache settings. For example, what's the difference between these two settings

hibernate.cache.queries
hibernate.cache.use_query_cache

On top of the links provided above, my cursory search provided some very old results. I'm not sure if these are still relevant but they gave me a better understanding of what might be happening.

region:
factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
use_query_cache: true
use_query_cache: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmiranda as Alan is out today, I'll answer, because I advised Alan to set this property to false globally.
Alan discovered, that the view data is not refreshed and adding this:

cache(false)

to the createCriteria caused the query to be working fine.
What came immediately to my mind was this hibernate setting, as not a long time ago I was digging into that and read a bit about it. Setting this to false fixed the issue and we were scared that this could be a big bug going forward, we disabled this for now globally.

I know we'd expect that the caching should be enabled explicitly (it shouldn't be enabled by default in this case for createCriteria), but I think the reason for that might be how mapping in InvoiceItemCandidate is defined (3rd line):

static mapping = {
    id generator: 'uuid'
    version false
    cache usage: "read-only"
}

so maybe Hibernate/Grails automatically for domains defined like that, enables the caching (to be figured out).

I agree we should have a spike ticket regarding this caching (and I believe you made a comment in my hibernate document about that, to create the ticket).
For now this LGTM.

cc @alannadolny @awalkowiak @drodzewicz

@awalkowiak awalkowiak merged commit 7036613 into feature/upgrade-to-grails-3.3.10 Jul 10, 2023
@awalkowiak awalkowiak deleted the OBGM-559-fix branch July 10, 2023 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants