diff --git a/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java index 5fbec53e4..20b1aacd1 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java @@ -93,7 +93,7 @@ final class SimpleJpaQuery extends AbstractJpaQuery { .createNativeQuery(sortedQueryString, method.getReturnedObjectType()); } else { query = method.isModifyingQuery() ? getEntityManager().createQuery(sortedQueryString) : getEntityManager() - .createQuery(sortedQueryString, method.getReturnedObjectType()); + .createQuery(sortedQueryString); } return createBinder(values).bindAndPrepare(query); diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index 711a8ce6e..83fa6ecb5 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -32,6 +32,7 @@ import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -735,6 +736,22 @@ public class UserRepositoryTests { assertThat(result, hasItem(firstUser)); } + /** + * Ignored until the query declaration is supported by OpenJPA. + */ + @Test + @Ignore + public void executesAnnotatedCollectionMethodCorrectly() { + + flushTestUsers(); + firstUser.addColleague(thirdUser); + repository.save(firstUser); + + List result = null; // repository.findColleaguesFor(firstUser); + assertThat(result.size(), is(1)); + assertThat(result, hasItem(thirdUser)); + } + protected void flushTestUsers() { firstUser = repository.save(firstUser); diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index 4f310f930..20bff35e6 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java @@ -207,4 +207,10 @@ public interface UserRepository extends JpaRepository, JpaSpecifi * @see DATAJPA-132 */ List findByActiveFalse(); + + /** + * Commented out until OpenJPA supports this. + */ + // @Query("select u.colleagues from User u where u = ?1") + // List findColleaguesFor(User user); }