Giter Club home page Giter Club logo

Comments (2)

KerchumA222 avatar KerchumA222 commented on June 14, 2024

Just a heads up: you don't need def in front of a type. For example: def List listScientificNamedQuery = Book.namedQueryScientificOnly.list() should be List listScientificNamedQuery = Book.namedQueryScientificOnly.list()

Also it is much easier to use integration or unit tests for this kind of thing.

from gorm-hibernate5.

benrhine avatar benrhine commented on June 14, 2024

After doing some research on this I have created an updated example with integration tests here to help narrow down the exact case of what is happening.

NOTE: Please refer to the example BookIntSpec for all working cases.

There are two failing cases. The one which you mentioned (which is returning a detached criteria and trying to add to it)

Book.whereScientificOnly.countByAuthor(author)

and hand writting the detached criteria for the above also fails in the same manner.

final criteria = new DetachedCriteria(Book).build {
    eq 'isScientific', true
}
final count = criteria.countByAuthor(author)

In both of the above queries it generates the same SQL (leaves out the isScientific)

Hibernate: select count(*) as y0_ from book this_ where this_.author_id=? limit ?

It appears to me that when executing the query this way the initial criteria of if isScientific is true is ignored or the statement is not executed as a whole. I have a suspicion that the the DetachedCriteria is not executing as a single statement because if you run either Book.whereScientificOnly or

final criteria = new DetachedCriteria(Book).build {
    eq 'isScientific', true
}
criteria.list()

you will get expected return results. Similar if you run Book.countByAuthor(author) or

final criteria = new DetachedCriteria(Book).build {}
final count = criteria.countByAuthor(author)

You will also get the expected counts.

In the doc on where queries it specifically discusses how detached criteria are lazy initialized and don't execute unless called which may be related to to the odd results of the above 2 cases

from gorm-hibernate5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.