Skip to content

Commit

Permalink
Merge pull request spring-attic#23 from zyro23/GRAILS-9750
Browse files Browse the repository at this point in the history
potential fix for GRAILS-9750
  • Loading branch information
graemerocher committed May 11, 2014
2 parents 17d0436 + 88fa5e5 commit 16e6c61
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
@@ -0,0 +1,57 @@
package org.grails.datastore.gorm

import grails.gorm.tests.GormDatastoreSpec

import javax.persistence.Entity

import org.grails.datastore.gorm.query.transform.ApplyDetachedCriteriaTransform

import spock.lang.Issue

/**
* ensure that detached criteria ast transformations work on annotated jpa entities
*/
@ApplyDetachedCriteriaTransform
@Issue('GRAILS-9750')
class DetachedCriteriaJpaEntitySpec extends GormDatastoreSpec {

@Override
List getDomainClasses() {
return [Todo]
}

def "test a where query on a jpa entity"() {
given: "a todo"
new Todo(title: "todo").save(flush: true)
session.clear()

when: "query without restrictions"
def results = Todo.findAll {}

then: "one todo"
results.size() == 1

when: "query with matching restrictions"
results = Todo.findAll {
title == "todo"
}

then: "one todo"
results.size() == 1

when: "query with not matching restrictions"
results = Todo.findAll {
title == "no match"
}

then: "no todo"
results.size() == 0
}

}

@javax.persistence.Entity
class Todo {
Long id
String title
}
Expand Up @@ -1323,6 +1323,9 @@ protected boolean isDomainClass(ClassNode classNode) {
if (Entity.class.getName().equals(className)) {
return true;
}
if (javax.persistence.Entity.class.getName().equals(className)) {
return true;
}
}
}
return false;
Expand Down

0 comments on commit 16e6c61

Please sign in to comment.