DATAJPA-496 - Fixed join creation for element collection attributes.

QueryUtils.toExpressionRecursively(…) now also creates joins for attributes mapped to an @ElementCollection.

Original pull request: #68.
This commit is contained in:
Thomas Darimont
2014-03-13 12:36:42 +01:00
committed by Oliver Gierke
parent 5438c44c8f
commit 07976eac9c
5 changed files with 50 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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<String> attributes;
/**
* Creates a new empty instance of {@code User}.
*/
@@ -85,6 +88,7 @@ public class User {
this.active = true;
this.roles = new HashSet<Role>();
this.colleagues = new HashSet<User>();
this.attributes = new HashSet<String>();
this.createdAt = new Date();
}
@@ -329,6 +333,20 @@ public class User {
return this.getId().equals(that.getId());
}
/**
* @return the attributes
*/
public Set<String> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Set<String> attributes) {
this.attributes = attributes;
}
/*
* (non-Javadoc)
*

View File

@@ -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() {}
}

View File

@@ -1280,6 +1280,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<User> result = repository.findByAttributesIn(new HashSet<String>(Arrays.asList("cool", "hip")));
assertThat(result, hasSize(2));
assertThat(result, hasItems(firstUser, secondUser));
}
private Page<User> executeSpecWithSort(Sort sort) {
flushTestUsers();

View File

@@ -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;
@@ -311,4 +312,9 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
* @see DATAJPA-486
*/
Slice<User> findSliceByLastname(String lastname, Pageable pageable);
/**
* @see DATAJPA-496
*/
List<User> findByAttributesIn(Set<String> attributes);
}