|
24 | 24 | import org.slf4j.Logger; |
25 | 25 | import org.slf4j.LoggerFactory; |
26 | 26 | import org.springframework.data.mapping.Association; |
| 27 | +import org.springframework.data.mapping.PropertyPath; |
27 | 28 | import org.springframework.data.mapping.model.MappingException; |
28 | 29 | import org.springframework.data.mybatis.mapping.*; |
29 | 30 | import org.springframework.data.mybatis.repository.dialect.Dialect; |
@@ -126,11 +127,26 @@ private String buildQueryCondition(boolean basic) { |
126 | 127 | Association<MybatisPersistentProperty> ass = property.getAssociation(); |
127 | 128 | if (ass instanceof MybatisManyToOneAssociation) { |
128 | 129 | MybatisManyToOneAssociation association = (MybatisManyToOneAssociation) ass; |
129 | | - MybatisPersistentProperty leafProperty = association.getObversePersistentEntity().getPersistentProperty(part.getProperty().getLeafProperty().getSegment()); |
130 | | - if (null == leafProperty) { |
131 | | - throw new MybatisQueryException("can not find property: " + part.getProperty().getLeafProperty().getSegment() + " from entity: " + association.getObversePersistentEntity().getName()); |
| 130 | + |
| 131 | + MybatisPersistentEntity<?> obversePersistentEntity = association.getObversePersistentEntity(); |
| 132 | + if (null == obversePersistentEntity) { |
| 133 | + throw new MybatisQueryException("can not find obverse persistent entity."); |
| 134 | + } |
| 135 | + |
| 136 | + PropertyPath leaf = part.getProperty().getLeafProperty(); |
| 137 | + |
| 138 | + if (obversePersistentEntity.getType() == leaf.getType()) { |
| 139 | + |
| 140 | + //columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + dialect.wrapColumnName(obversePersistentEntity.getIdProperty().getColumnName()); |
| 141 | + throw new UnsupportedOperationException("findBy{Association Model} Style is not support now."); |
| 142 | + |
| 143 | + } else { |
| 144 | + MybatisPersistentProperty leafProperty = obversePersistentEntity.getPersistentProperty(leaf.getSegment()); |
| 145 | + if (null == leafProperty) { |
| 146 | + throw new MybatisQueryException("can not find property: " + leaf.getSegment() + " from entity: " + obversePersistentEntity.getName()); |
| 147 | + } |
| 148 | + columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + dialect.wrapColumnName(leafProperty.getColumnName()); |
132 | 149 | } |
133 | | - columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + dialect.wrapColumnName(leafProperty.getColumnName()); |
134 | 150 | } else if (ass instanceof MybatisEmbeddedAssociation) { |
135 | 151 | columnName = quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(ass.getObverse().getColumnName()); |
136 | 152 | } |
|
0 commit comments