@@ -787,24 +787,85 @@ public void doWithPersistentProperty(PersistentProperty<?> pp) {
787
787
788
788
private void buildInnerResultMap (final StringBuilder builder , final MybatisPersistentEntity <?> persistentEntity , final String prefix ) {
789
789
790
+ final StringBuilder constructorBuilder = new StringBuilder ();
791
+ final StringBuilder resultBuilder = new StringBuilder ();
792
+
793
+ PreferredConstructor <?, MybatisPersistentProperty > persistenceConstructor = persistentEntity .getPersistenceConstructor ();
794
+ if (null != persistenceConstructor && persistenceConstructor .hasParameters ()) {
795
+ constructorBuilder .append ("<constructor>" );
796
+ }
797
+
798
+
790
799
persistentEntity .doWithProperties (new SimplePropertyHandler () {
791
800
@ Override
792
801
public void doWithPersistentProperty (PersistentProperty <?> pp ) {
793
802
MybatisPersistentProperty property = (MybatisPersistentProperty ) pp ;
803
+
804
+ if (persistentEntity .isConstructorArgument (property )) {
805
+ if (property .isIdProperty ()) {
806
+
807
+ if (property .isCompositeId ()) {
808
+
809
+ MybatisPersistentEntityImpl <?> idEntity = context .getPersistentEntity (property .getActualType ());
810
+ if (null != idEntity ) {
811
+ idEntity .doWithProperties (new SimplePropertyHandler () {
812
+ @ Override
813
+ public void doWithPersistentProperty (PersistentProperty <?> pp ) {
814
+ MybatisPersistentProperty property = (MybatisPersistentProperty ) pp ;
815
+ builder .append (String .format ("<idArg property=\" %s\" column=\" %s\" javaType=\" %s\" jdbcType=\" %s\" />" ,
816
+ property .getName () + "." + property .getName (),
817
+ alias (prefix + property .getName ()),
818
+ property .getActualType ().getName (),
819
+ property .getJdbcType ()
820
+ ));
821
+ }
822
+ });
823
+ }
824
+
825
+ } else {
826
+ builder .append (String .format ("<idArg property=\" %s\" column=\" %s\" javaType=\" %s\" jdbcType=\" %s\" />" ,
827
+ property .getName (),
828
+ alias (prefix + property .getName ()),
829
+ property .getActualType ().getName (),
830
+ property .getJdbcType ()
831
+ ));
832
+ }
833
+
834
+
835
+ } else {
836
+ constructorBuilder .append (String .format ("<arg property=\" %s\" column=\" %s\" javaType=\" %s\" jdbcType=\" %s\" "
837
+ + (null != property .getSpecifiedTypeHandler () ? (" typeHandler=\" " + property .getSpecifiedTypeHandler ().getName () + "\" " ) : "" )
838
+ + " />" ,
839
+ property .getName (),
840
+ alias (prefix + property .getName ()),
841
+ property .getActualType ().getName (),
842
+ property .getJdbcType ()
843
+ ));
844
+ }
845
+ return ;
846
+ }
847
+
848
+
794
849
if (property .isIdProperty ()) {
795
- buildInnerResultMapId (builder , property , prefix );
850
+ buildInnerResultMapId (resultBuilder , property , prefix );
796
851
return ;
797
852
}
798
- builder .append (String .format ("<result property=\" %s\" column=\" %s\" javaType=\" %s\" jdbcType=\" %s\" " + (
799
- null != property .getSpecifiedTypeHandler () ? (" typeHandler=\" " + property .getSpecifiedTypeHandler ().getName () + "\" " ) : ""
800
- ) + " />" ,
853
+ resultBuilder .append (String .format ("<result property=\" %s\" column=\" %s\" javaType=\" %s\" jdbcType=\" %s\" "
854
+ + ( null != property .getSpecifiedTypeHandler () ? (" typeHandler=\" " + property .getSpecifiedTypeHandler ().getName () + "\" " ) : "" )
855
+ + " />" ,
801
856
property .getName (),
802
857
alias (prefix + property .getName ()),
803
858
property .getActualType ().getName (),
804
859
property .getJdbcType ()
805
860
));
806
861
}
807
862
});
863
+
864
+
865
+ if (null != persistenceConstructor && persistenceConstructor .hasParameters ()) {
866
+ constructorBuilder .append ("</constructor>" );
867
+ }
868
+ builder .append (constructorBuilder ).append (resultBuilder );
808
869
}
809
870
810
871
private void buildInnerToOneAssociationResultMap (final StringBuilder builder , final PersistentProperty <? extends PersistentProperty <?>> inverse ) {
@@ -880,13 +941,16 @@ private void buildInnerToManyAssociationResultMap(final StringBuilder builder, P
880
941
MybatisPersistentEntityImpl <?> inversePersistentEntity = context .getPersistentEntity (actualType );
881
942
if (null != inversePersistentEntity ) {
882
943
buildInnerResultMap (builder , inversePersistentEntity , inverse .getName () + "." );
944
+
945
+
883
946
}
884
947
builder .append ("</collection>" );
885
948
}
886
949
887
950
private void buildResultMap (final StringBuilder builder ) {
888
951
builder .append ("<resultMap id=\" ResultMap\" type=\" " + domainClass .getName () + "\" >" );
889
952
953
+
890
954
buildInnerResultMap (builder , persistentEntity , "" );
891
955
892
956
persistentEntity .doWithAssociations (new AssociationHandler <MybatisPersistentProperty >() {
@@ -902,8 +966,10 @@ public void doWithAssociation(Association<MybatisPersistentProperty> ass) {
902
966
buildInnerToOneAssociationResultMap (builder , inverse );
903
967
return ;
904
968
}
905
- if (null != inverse .findAnnotation (OneToMany .class ) || null != inverse .findAnnotation (ManyToMany .class )) {
969
+
970
+ if (ass instanceof MybatisOneToManyAssociation ) {
906
971
buildInnerToManyAssociationResultMap (builder , inverse );
972
+ return ;
907
973
}
908
974
909
975
}
0 commit comments