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 fd2e3baf2..6628a2c2e 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 @@ -450,7 +450,7 @@ public abstract class QueryUtils { propertyPathModel = from.get(property.getSegment()).getModel(); } - if (property.isCollection() || requiresJoin(propertyPathModel)) { + if (requiresJoin(propertyPathModel)) { Join join = getOrCreateJoin(from, property.getSegment()); return (Expression) (property.hasNext() ? toExpressionRecursively(join, property.next()) : join); } else { @@ -481,7 +481,7 @@ public abstract class QueryUtils { Class associationAnnotation = ASSOCIATION_TYPES.get(attribute.getPersistentAttributeType()); if (associationAnnotation == null) { - return false; + return true; } Member member = attribute.getJavaMember(); 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 210fd60fa..a2ce46402 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 @@ -26,6 +26,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.NamedQuery; @@ -60,6 +61,8 @@ public class User { @Embedded private Address address; + @Lob private byte[] binaryData; + /** * Creates a new empty instance of {@code User}. */ @@ -291,6 +294,20 @@ public class User { this.address = address; } + /** + * @param binaryData the binaryData to set + */ + public void setBinaryData(byte[] binaryData) { + this.binaryData = binaryData; + } + + /** + * @return the binaryData + */ + public byte[] getBinaryData() { + return binaryData; + } + /* * (non-Javadoc) * 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 ba6bb1eb0..cdb4b784c 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -1196,6 +1196,22 @@ public class UserRepositoryTests { assertThat(page.getContent().get(3), is(thirdUser)); } + /** + * @see DATAJPA-454 + */ + @Test + public void findsUserByBinaryDataReference() throws Exception { + + byte[] data = "Woho!!".getBytes("UTF-8"); + firstUser.setBinaryData(data); + + flushTestUsers(); + + List result = repository.findByBinaryData(data); + assertThat(result, hasSize(1)); + assertThat(result, hasItem(firstUser)); + } + private Page executeSpecWithSort(Sort sort) { flushTestUsers(); diff --git a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java index 682b4c166..cc979cc2f 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java @@ -90,6 +90,21 @@ public class QueryUtilsIntegrationTests { QueryUtils.toExpressionRecursively(root, PropertyPath.from("customer", Order.class)); } + /** + * @see DATAJPA-454 + */ + @Test + public void createsJoingToTraverseCollectionPath() { + + CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(User.class); + Root root = query.from(User.class); + + QueryUtils.toExpressionRecursively(root, PropertyPath.from("colleaguesLastname", User.class)); + + assertThat(root.getJoins(), hasSize(1)); + } + protected void assertNoJoinRequestedForOptionalAssociation(Root root) { assertThat(root.getJoins(), is(empty())); } 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 3f506dfa0..42f18dc0f 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 @@ -288,4 +288,9 @@ public interface UserRepository extends JpaRepository, JpaSpecifi * @see DATAJPA-405 */ List findAllByOrderByLastnameAsc(); + + /** + * @see DATAJPA-454 + */ + List findByBinaryData(byte[] data); }