question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter on join table attribute

See original GitHub issue

Firstly, thanks for your open source contribution.

I would like to know if what I am trying is supported by the specification-arg-resolver. For example, I would like to retrieve all customers whose city of address matches ‘Montreal’ in the below entity model.

@Entity
public class Customer implements Serializable {
    @Id @GeneratedValue
     private Long id;
    @OneToMany
    @JoinColumn(name = "customerId")
    private List<Address> addresses;
}

@Entity
public class Address implements Serializable {
    @Id
    private Long contactId;
    private String city;
}

I tried below spec annotation, but it didn’t work.

@RequestMapping(value = "", params = { "city" })
@ResponseBody
public Iterable<Customer> filterCustomersByCity(
        @JoinFetch(paths = {"addresses" })
        @Spec(path="addresses.city", params="city", spec=In.class)
        final Specification<Customer> customersByCitySpec) {
         return customerRepo.findAll(customersByCitySpec);

}

I get below error

java.lang.IllegalStateException: Illegal attempt to dereference path source [null.addresses] of basic type at org.hibernate.jpa.criteria.path.AbstractPathImpl.illegalDereference(AbstractPathImpl.java:98) at org.hibernate.jpa.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:182) at net.kaczmarzyk.spring.data.jpa.domain.PathSpecification.path(PathSpecification.java:42) at net.kaczmarzyk.spring.data.jpa.domain.In.toPredicate(In.java:64) at org.springframework.data.jpa.domain.Specifications$1.toPredicate(Specifications.java:64) at org.springframework.data.jpa.domain.Specifications.toPredicate(Specifications.java:114) at net.kaczmarzyk.spring.data.jpa.domain.Conjunction.toPredicate(Conjunction.java:58)

On debugging, I see it is not able to fetch city field. What am I doing wrong? Could you please point me in right direction.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tkaczmarzykcommented, Nov 16, 2017

v1.0.0 with join support has been released.

1reaction
ekalabscommented, May 13, 2016

I was in assumption that ’ @JoinFetch(paths = {“addresses” }) ’ along with ’ @Spec(path=“addresses.city” ’ reference to OneToMany attribute ‘addresses’ + join-table attribute ‘city’ will produce the specification object with join + distinct you mentioned in option 2.

I would be happy to work with you on this. Let me know how I can help. Thanks for your prompt reply and effort.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering a joined table - mysql - Stack Overflow
select avg( e.published and a.type not in ('large', 'medium') ) from events e join attributes a on e.id = a.event_id;.
Read more >
How do you filter a layer on a joined table in QGIS?
I found these 2 feature requests which seem to confirm that you can't filter the layer on the joined table. The workaround is...
Read more >
Filter on a join table attribute not working in postgres - Get Help
I am trying to filter the table on customerId obtained by joining users and registrations. SELECT "Users"."Customer ID" AS "Customer ID", ...
Read more >
Using ON Versus WHERE Clauses to Combine and Filter ...
In an SQL query, data can be filtered in the WHERE clause or the ON clause of a join. This guide will examine...
Read more >
Filtering joins - dplyr
Filtering joins filter rows from x based on the presence or absence of matches in y : semi_join() return all rows from x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found