File tree Expand file tree Collapse file tree 3 files changed +10
-11
lines changed
main/java/org/apache/ibatis/mapping
test/java/org/apache/ibatis/submitted/resultmapwithassociationstest Expand file tree Collapse file tree 3 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -140,15 +140,15 @@ public ResultMapping build() {
140
140
private void validate () {
141
141
// Issue #697: cannot define both nestedQueryId and nestedResultMapId
142
142
if (resultMapping .nestedQueryId != null && resultMapping .nestedResultMapId != null ) {
143
- throw new IllegalStateException ("Cannot define both nestedQueryId and nestedResultMapId in property " + resultMapping .property );
143
+ throw new IllegalStateException ("Cannot define both nestedQueryId and nestedResultMapId in mapping " + resultMapping .property );
144
144
}
145
145
// Issue #5: there should be no mappings without typehandler
146
146
if (resultMapping .nestedQueryId == null && resultMapping .nestedResultMapId == null && resultMapping .typeHandler == null ) {
147
- throw new IllegalStateException ("No typehandler found for property " + resultMapping .property );
148
- }
149
- // Issue #4: column is mandatory on nested queries
150
- if (resultMapping .nestedQueryId ! = null && resultMapping .column == null && resultMapping .composites .size () == 0 ) {
151
- throw new IllegalStateException ("Missing column attribute for nested select in property " + resultMapping .property );
147
+ throw new IllegalStateException ("No typehandler found for mapping " + resultMapping .property );
148
+ }
149
+ // Issue #4 and GH #39 : column is optional only in nested resultmaps but not in the rest
150
+ if (resultMapping .nestedResultMapId = = null && resultMapping .column == null && resultMapping .composites .size () == 0 ) {
151
+ throw new IllegalStateException ("Missing column attribute for nested select in mapping " + resultMapping .property );
152
152
}
153
153
if (resultMapping .getResultSet () != null ) {
154
154
int numColums = 0 ;
Original file line number Diff line number Diff line change 20
20
21
21
<mapper namespace =" org.apache.ibatis.submitted.resultmapwithassociationstest.Mapper" >
22
22
<resultMap id =" personRM" type =" org.apache.ibatis.submitted.resultmapwithassociationstest.Person" >
23
- <id column =" id" />
23
+ <id property =" id" />
24
24
<association property =" address" column =" id_address" javaType =" org.apache.ibatis.submitted.resultmapwithassociationstest.Address" >
25
25
<id property =" id" column =" address_id" />
26
26
</association >
Original file line number Diff line number Diff line change 19
19
import java .sql .Connection ;
20
20
import java .util .List ;
21
21
22
+ import org .apache .ibatis .exceptions .PersistenceException ;
22
23
import org .apache .ibatis .io .Resources ;
23
24
import org .apache .ibatis .jdbc .ScriptRunner ;
24
25
import org .apache .ibatis .session .SqlSession ;
25
26
import org .apache .ibatis .session .SqlSessionFactory ;
26
27
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
27
28
import org .junit .Assert ;
28
- import org .junit .BeforeClass ;
29
29
import org .junit .Test ;
30
30
31
31
public class ResultMapWithAssociationsTest {
32
32
33
33
private static SqlSessionFactory sqlSessionFactory ;
34
34
35
- @ BeforeClass
36
- public static void setUp () throws Exception {
35
+ @ Test ( expected = PersistenceException . class )
36
+ public void testMissingColumn () throws Exception {
37
37
// create a SqlSessionFactory
38
38
Reader reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/resultmapwithassociationstest/mybatis-config.xml" );
39
39
sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
@@ -50,7 +50,6 @@ public static void setUp() throws Exception {
50
50
session .close ();
51
51
}
52
52
53
- @ Test
54
53
public void shouldFindAllPersonRecordsWithAssociatedAddressRecord () {
55
54
SqlSession sqlSession = sqlSessionFactory .openSession ();
56
55
try {
You can’t perform that action at this time.
0 commit comments