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

Collection like properties of entities without id property need special handling [DATAJDBC-223] #449

spring-projects-issues opened this issue Jun 8, 2018 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Jun 8, 2018

Jens Schauder opened DATAJDBC-223 and commented

I just added the id != null checks in the EntityRowMapper shown below which makes it obvious that some special handling is needed since the effective id of the parent entity is the id of its parent entity plus the value of the key column.

	public T mapRow(ResultSet resultSet, int rowNumber) {

		T result = createInstance(entity, resultSet, "");

		ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(result),

		Object id = idProperty == null ? null : readFrom(resultSet, idProperty, "");

		for (JdbcPersistentProperty property : entity) {

			if (property.isCollectionLike() && id != null) {
				propertyAccessor.setProperty(property, accessStrategy.findAllByProperty(id, property));
			} else if (property.isMap() && id != null) {

				Iterable<Object> allByProperty = accessStrategy.findAllByProperty(id, property);
				propertyAccessor.setProperty(property, ITERABLE_OF_ENTRY_TO_MAP_CONVERTER.convert(allByProperty));
			} else {
				propertyAccessor.setProperty(property, readFrom(resultSet, property, ""));

		return result;

Issue Links:

  • DATAJDBC-359 Chains of entities without id should work and reference the topmost entity
    ("depends on")

  • DATAJDBC-291 Nested data structure with Spring Data JDBC

  • DATAJDBC-366 Repository#findAll() method don't work with 1:n relation

Referenced from: pull request #153

Copy link

@spring-projects-issues spring-projects-issues commented Oct 1, 2018

Jens Schauder commented

The same is true for one-to-one references

Copy link

@spring-projects-issues spring-projects-issues commented Apr 10, 2019

Jens Schauder commented

Created a separate issue for the 1:1 relationship case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants