diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 66e8338f8..265a83a7b 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -118,6 +118,7 @@ public abstract class QueryUtils { persistentAttributeTypes.put(ONE_TO_MANY, null); persistentAttributeTypes.put(MANY_TO_ONE, ManyToOne.class); persistentAttributeTypes.put(MANY_TO_MANY, null); + persistentAttributeTypes.put(ELEMENT_COLLECTION, null); ASSOCIATION_TYPES = Collections.unmodifiableMap(persistentAttributeTypes); } diff --git a/src/test/java/org/springframework/data/jpa/domain/sample/User.java b/src/test/java/org/springframework/data/jpa/domain/sample/User.java index 1453c1cbb..c2031f50a 100644 --- a/src/test/java/org/springframework/data/jpa/domain/sample/User.java +++ b/src/test/java/org/springframework/data/jpa/domain/sample/User.java @@ -21,6 +21,7 @@ import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -63,6 +64,8 @@ public class User { @Lob private byte[] binaryData; + @ElementCollection private Set attributes; + /** * Creates a new empty instance of {@code User}. */ @@ -85,6 +88,7 @@ public class User { this.active = true; this.roles = new HashSet(); this.colleagues = new HashSet(); + this.attributes = new HashSet(); this.createdAt = new Date(); } @@ -329,6 +333,20 @@ public class User { return this.getId().equals(that.getId()); } + /** + * @return the attributes + */ + public Set getAttributes() { + return attributes; + } + + /** + * @param attributes the attributes to set + */ + public void setAttributes(Set attributes) { + this.attributes = attributes; + } + /* * (non-Javadoc) * diff --git a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java index 9234f430e..d86e36b87 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java @@ -22,6 +22,7 @@ import org.springframework.test.context.ContextConfiguration; * Testcase to run {@link UserRepository} integration tests on top of EclipseLink. * * @author Oliver Gierke + * @author Thomas Darimont */ @ContextConfiguration(value = "classpath:eclipselink.xml") public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserRepositoryTests { @@ -67,4 +68,10 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi */ @Override public void sortByAssociationPropertyInPageableShouldUseLeftOuterJoin() {} + + /** + * Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 is resolved. + */ + @Override + public void findByElementCollectionAttribute() {} } 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 f4dd3ec7c..da2a976f6 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -1262,6 +1262,24 @@ public class UserRepositoryTests { assertThat(page.getContent().get(3), is(firstUser)); } + /** + * @see DATAJPA-496 + */ + @Test + public void findByElementCollectionAttribute() { + + firstUser.getAttributes().add("cool"); + secondUser.getAttributes().add("hip"); + thirdUser.getAttributes().add("rockstar"); + + flushTestUsers(); + + List result = repository.findByAttributesIn(new HashSet(Arrays.asList("cool", "hip"))); + + assertThat(result, hasSize(2)); + assertThat(result, hasItems(firstUser, secondUser)); + } + private Page executeSpecWithSort(Sort sort) { flushTestUsers(); 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 5510f80f8..4846d2e0f 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 @@ -18,6 +18,7 @@ package org.springframework.data.jpa.repository.sample; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; import javax.persistence.QueryHint; @@ -305,4 +306,9 @@ public interface UserRepository extends JpaRepository, JpaSpecifi * @see DATAJPA-454 */ List findByBinaryData(byte[] data); + + /** + * @see DATAJPA-496 + */ + List findByAttributesIn(Set attributes); }