2

I am using the recently released QBE functionality through spring-data-jpa. Everything seems to work just fine, with the one exception being that fields annotated as @JoinTable do not seem to work. I've tried simple primitives on the entity, as well as a @JoinColumn relationship, and the query performs as expected. However, once I tried to populate a Set of objects that were a @JoinTable relationship, that data does not become part of my query (I checked the SQL that is logged). We are using Hibernate as our JPA provider, so perhaps the issue is with the implementation. I'm just going to assume I'm doing something wrong for now.

@ManyToMany
@JoinTable(name = "join_table", joinColumns = @JoinColumn(name = "userid", nullable = false), inverseJoinColumns = @JoinColumn(name = "groupid", nullable = false))
private Set<Group> groups= new HashSet<>(0);

That's the annotated field that is not working. In order to populate it for my QBE I simply create a new group with a specific name I am looking for. I need the user to belong to that group in order to return. However, the SQL that is generated does not include anything about the group in the where clause.

Example<User> example = Example.of(user);

return userRepo.findAll(example, pageable);

And the snippet that calls the JPA repository.

Any ideas would be greatly appreciated.

Demon Coldmist
  • 2,560
  • 2
  • 13
  • 21
Troy Doty
  • 23
  • 4

1 Answers1

2

At this time the QBE feature of Spring Data JPA only supports SingularAttributes. Therefore @JoinTable cannot be used. Please have a look at the "Executing an Example" section in reference manual.

Christoph Strobl
  • 6,491
  • 25
  • 33
  • Thanks for the reply. If I need a PluralAttribute as part of my query, is there a way to combine QBE with something else in order to accomplish this, or do I need to just not use QBE until support is added? – Troy Doty Aug 23 '16 at 20:54
  • you can try to build you own `Specification` like it is done in [ExampleSpecification](https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java#L806), add the paths you need and then pass it on to the `JpaSpecificationExecutor`. – Christoph Strobl Aug 24 '16 at 08:27