Skip to content

Unintentional fetch when domain class contains dateCreated property or a closure event #14546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Macoshark opened this issue Oct 9, 2018 · 0 comments

Comments

@Macoshark
Copy link

Grails fetches proxied domain class references from database unnecessarily when domain class includes the auto timestamped "dateCreated" field or any closure event method (beforeUpdate, afterUpdate, beforeInsert, etc). They are not fetched because of validation and setting validate to false during save has no effect.

Setting autoTimestamp to false in the domain class mapping and removing any closure event methods removes the problem.

The problem can be reproduced on at least grails 2.4.5, 2.5.5 and 2.5.6. It can not be reproduced on grails 3.3.8.

Tested on

Task List

  • [ x] Steps to reproduce provided
  • [ x
    DateCreated2.zip
    ] Stacktrace (if present) provided
  • [ x] Example that reproduces the problem uploaded to Github
  • [ x] Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a domain class hierarchy where one domain (Review) references other domains (Product, Person) via member variables
  2. Add a "dateCreated" property in the domain that references others (Review).
  3. Add "beforeInsert", "afterUpdate" or any other closure event method in the domain that references others.
  4. Create a new instance of the domain that references others (Review)
  5. Set referenced domains by getting a hibernate proxy with the load() method.
  6. Save the created domain instance.

Expected Behaviour

Database is accessed only once to insert the newly created domain (Review). Other domains (Product, Person) referenced via hibernate proxies are not fetched.

Actual Behaviour

All referenced domains are fetched with separate trips to the database.

Environment Information

  • Operating System:
    Macos 10.13.6
  • Grails Version:
    2.5.6
  • JDK Version:
    1.7.0_80
  • Container Version (If Applicable):

Example Application

  • TODO: link to github repository with example that reproduces the issue
@jameskleeh jameskleeh transferred this issue from apache/grails-core Nov 1, 2018
@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants