Skip to content

Commit 31eeba7

Browse files
schaudergregturn
authored andcommitted
DATAJDBC-142 - Using getName instead of getColumnName for constructing PropertyPaths.
1 parent 964f319 commit 31eeba7

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public List<PropertyPath> referencedEntities(Class<?> rootType, PropertyPath pat
9191
if (property.isEntity()) {
9292

9393
PropertyPath nextPath = path == null ? PropertyPath.from(property.getName(), rootType)
94-
: path.nested(property.getColumnName());
94+
: path.nested(property.getName());
9595
paths.add(nextPath);
9696
paths.addAll(referencedEntities(rootType, nextPath));
9797
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.mapping.model;
17+
18+
import org.junit.Test;
19+
import org.springframework.data.mapping.PropertyPath;
20+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
21+
22+
import java.util.List;
23+
24+
import static org.assertj.core.api.Assertions.*;
25+
import static org.mockito.Mockito.*;
26+
27+
/**
28+
* Unit tests for {@link JdbcMappingContext}.
29+
*
30+
* @author Jens Schauder
31+
*/
32+
public class JdbcMappingContextUnitTests {
33+
34+
NamingStrategy namingStrategy = new DefaultNamingStrategy();
35+
NamedParameterJdbcOperations jdbcTemplate = mock(NamedParameterJdbcOperations.class);
36+
ConversionCustomizer customizer = mock(ConversionCustomizer.class);
37+
38+
@Test // DATAJDBC-142
39+
public void referencedEntitiesGetFound() {
40+
41+
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer);
42+
43+
List<PropertyPath> propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null);
44+
45+
assertThat(propertyPaths) //
46+
.extracting(PropertyPath::toDotPath) //
47+
.containsExactly( //
48+
"one.two", //
49+
"one" //
50+
);
51+
}
52+
53+
@Test // DATAJDBC-142
54+
public void propertyPathDoesNotDependOnNamingStrategy() {
55+
56+
namingStrategy = mock(NamingStrategy.class);
57+
58+
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer);
59+
60+
List<PropertyPath> propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null);
61+
62+
assertThat(propertyPaths) //
63+
.extracting(PropertyPath::toDotPath) //
64+
.containsExactly( //
65+
"one.two", //
66+
"one" //
67+
);
68+
}
69+
70+
private static class DummyEntity {
71+
72+
String simpleProperty;
73+
74+
LevelOne one;
75+
}
76+
77+
private static class LevelOne {
78+
LevelTwo two;
79+
}
80+
81+
private static class LevelTwo {
82+
String someValue;
83+
}
84+
}

0 commit comments

Comments
 (0)