Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryDSL predicates with @ManyToOne relationships do not work #7

Open
darrachequesne opened this issue Mar 31, 2016 · 3 comments
Open
Labels

Comments

@darrachequesne
Copy link
Owner

Currently, @manytoone relationships with QDataTablesRepository break global search:

Server:

@Entity
public class User {
  @Id private Integer id;

  @ManyToOne
  @JoinColumn(name = "id_address")
  private Address address;
}

@Entity
public class Address {
  @Id private Integer id;
}

Client:

$('table#users').DataTable({
    columns : [ {
        data : 'id'
    }, {
        data : 'address.id',
        // searchable: false,
        render: function(data, type, row) {
            return data ? data : '';
        }
    }]
});

The countQuery issued by QueryDslJpaRepository.findAll(Predicate predicate, Pageable pageable) triggers the following query:

select count(user0_.id) as col_0_0_
  from user_ user0_
  cross join address address1_
  where
    user0_.id_address=address1_.id
    and (lower(cast(user0_.id as char)) like ? escape '\' 
    or lower(cast(address1_.id as char)) like ? escape '\')

To add a proper LEFT JOIN, an (ugly) workaround would be to manually add JPQLQuery countQuery = createQuery(predicate).leftJoin(entity.get("address")). But if someone has a better idea, I'm open to suggestions!

Update: since QueryDSL generates a leftJoin instead of an innerJoin when a sort is applied on the given column (ref), the following workaround works pretty well:

var table = $('table#users').DataTable({
     orderFixed: [ <your-column-id>, 'asc' ],
});
@Dazzel
Copy link

Dazzel commented Jul 28, 2017

Any news on this one? Tested the provided workaround but with no luck :(

@ShivanshCharak
Copy link

can i work on this?

@darrachequesne
Copy link
Owner Author

@ShivanshCharak yeah, sure 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants