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

QueryByExample identifier matching to handle self reference [DATAJPA-1125] #1470

Open
spring-projects-issues opened this issue Jun 1, 2017 · 2 comments
Assignees
Labels
type: enhancement

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Jun 1, 2017

Csongor Szita opened DATAJPA-1125 and commented

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

No further details from DATAJPA-1125

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jun 1, 2017

Csongor Szita commented

If you agree with the problem, I would like to send a pull request with a solution that handle identifier matching if the identifier attributes are PersistentAttributeType.BASIC.

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Oct 28, 2019

Jens Schauder commented

I'm not sure what Ids have to do with this, but a PR that adds a check to prevent infinite recursion would be very welcome

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

No branches or pull requests

2 participants