Skip to content
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

GORM Hibernate - detached criteria query composition ignores second detached criteria when not performed in same method #982

Closed
dspies opened this issue Aug 7, 2017 · 0 comments
Assignees
Milestone

Comments

@dspies
Copy link

dspies commented Aug 7, 2017

Similar issue to Issue #860

Steps to Reproduce

  1. Create new app in Grails 3.3.0
  2. Create simple domain class (Company) with static method that returns a DetachedCriteria instance
class Company {
  String name
  String ownerName

  static DetachedCriteria<Company> defaultCriteria(String companyName) {
    return Company.where {
      name == companyName
    }
  }
}
  1. Create dummy data
def init = { servletContext ->
  new Company(name: 'test', ownerName: 'don').save(flush: true)
  new Company(name: 'test', ownerName: 'jake').save(flush: true)
  new Company(name: 'test', ownerName: 'henry').save(flush: true)
  new Company(name: 'other', ownerName: 'amber').save(flush: true)
}
  1. Create simple controller class where the index method creates a DetachedCriteria instance from the Company domain class' static method's result, adds an additional where clause, and calls list() on the resulting DetachedCriteria instance
class CompanyController {
  def index = {
    DetachedCriteria<Company> exampleCriteria = Company.defaultCriteria('test')
    DetachedCriteria<Company> indexCriteria = exampleCriteria.where {
      ownerName == 'don'
    }
    respond indexCriteria.list()
  }
}

Expected Behaviour

The index method should return one Company object with the name 'test' and the ownerName 'don', which is a result of the composition of the two detached criteria objects.

Actual Behaviour

The index method returns the 3 Company objects with the name 'test', because only the first Detached Criteria instance is used, ignoring the second Detached Criteria instance altogether.

Environment Information

  • Operating System: Ubuntu 16.04
  • GORM Version: 6.1.6.RELEASE
  • Grails Version (if using Grails): 3.3.0
  • JDK Version:
    java version "1.8.0_144"
    Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Example Application

@graemerocher graemerocher modified the milestone: 6.1.7 Aug 18, 2017
@graemerocher graemerocher self-assigned this Aug 21, 2017
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

No branches or pull requests

2 participants