Skip to content

Commit 8ce721c

Browse files
author
Jarvis
committed
unsupport findBy{Model} now
1 parent e158192 commit 8ce721c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/main/java/org/springframework/data/mybatis/repository/query/PartTreeMybatisQuery.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626
import org.springframework.data.mapping.Association;
27+
import org.springframework.data.mapping.PropertyPath;
2728
import org.springframework.data.mapping.model.MappingException;
2829
import org.springframework.data.mybatis.mapping.*;
2930
import org.springframework.data.mybatis.repository.dialect.Dialect;
@@ -126,11 +127,26 @@ private String buildQueryCondition(boolean basic) {
126127
Association<MybatisPersistentProperty> ass = property.getAssociation();
127128
if (ass instanceof MybatisManyToOneAssociation) {
128129
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());
132149
}
133-
columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + dialect.wrapColumnName(leafProperty.getColumnName());
134150
} else if (ass instanceof MybatisEmbeddedAssociation) {
135151
columnName = quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(ass.getObverse().getColumnName());
136152
}

0 commit comments

Comments
 (0)