Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-1125

QueryByExample identifier matching to handle self reference

    XMLWordPrintable

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      The current QueryByExamplePredicateBuilder not handle cycling- and self-reference, so it throw StackOverflowException.

      For example if we have the below entity-s:

      	@Entity
      	class User{
      		@Id
      		Long id;
      		String firstName;
      		@ManyToOne
      		Address address;
      		//...
      	}
      
      	@Entity
      	class Address{
      		@Id
      		Long id;
      		String addressLine;
      		@CreatedBy
      		User user;
      	}
      

      And the below function:

      public List<User> getUsers(String firstName, Address address)
      	{
      		User user = new User();
      		user.setFisrtName(firstName);
      		user.setAddress(address);
      		return repository.findAll(Example.of(user));
      	}
      

      In the above example the address has reference the user (via audit createdBy) and the user has reference the address so it will throw StackOverflowException.

      The solution is to check if identifierAttribute (attributes) present in the example, and if so, then create Predicate Only for those.

      In the above example the QueryByExamplePredicateBuilder shuold create two Predicate:

      1. Equal to User.firstName
      2. Equal to User.Address.id

      Attachments

        Activity

          People

            schauder Jens Schauder
            szita.csongor Csongor Szita
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 1m
                1m
                Remaining:
                Remaining Estimate - 1m
                1m
                Logged:
                Time Spent - Not Specified
                Not Specified