@@ -583,15 +583,15 @@ private static void matchColumnsByProperty(Property property, Map<Column, Set<Pr
583
583
* If propertyName is null or empty, the IdentifierProperty is returned
584
584
*/
585
585
public static Property findPropertyByName (PersistentClass associatedClass , String propertyName ) {
586
- Property property = null ;
587
586
final Property idProperty = associatedClass .getIdentifierProperty ();
588
587
final String idName = idProperty == null ? null : idProperty .getName ();
589
588
try {
590
589
if ( isEmpty ( propertyName ) || propertyName .equals ( idName ) ) {
591
590
//default to id
592
- property = idProperty ;
591
+ return idProperty ;
593
592
}
594
593
else {
594
+ Property property = null ;
595
595
if ( propertyName .indexOf ( idName + "." ) == 0 ) {
596
596
property = idProperty ;
597
597
propertyName = propertyName .substring ( idName .length () + 1 );
@@ -602,13 +602,15 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
602
602
if ( property == null ) {
603
603
property = associatedClass .getProperty ( element );
604
604
}
605
+ else if ( property .isComposite () ) {
606
+ final var value = (Component ) property .getValue ();
607
+ property = value .getProperty ( element );
608
+ }
605
609
else {
606
- if ( !property .isComposite () ) {
607
- return null ;
608
- }
609
- property = ( (Component ) property .getValue () ).getProperty ( element );
610
+ return null ;
610
611
}
611
612
}
613
+ return property ;
612
614
}
613
615
}
614
616
catch ( MappingException e ) {
@@ -617,51 +619,57 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
617
619
if ( associatedClass .getIdentifierMapper () == null ) {
618
620
return null ;
619
621
}
620
- final var tokens = new StringTokenizer ( propertyName , "." , false );
621
- while ( tokens .hasMoreTokens () ) {
622
- final String element = tokens .nextToken ();
623
- if ( property == null ) {
624
- property = associatedClass .getIdentifierMapper ().getProperty ( element );
625
- }
626
- else {
627
- if ( !property .isComposite () ) {
622
+ else {
623
+ Property property = null ;
624
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
625
+ while ( tokens .hasMoreTokens () ) {
626
+ final String element = tokens .nextToken ();
627
+ if ( property == null ) {
628
+ property = associatedClass .getIdentifierMapper ().getProperty ( element );
629
+ }
630
+ else if ( property .isComposite () ) {
631
+ final var value = (Component ) property .getValue ();
632
+ property = value .getProperty ( element );
633
+ }
634
+ else {
628
635
return null ;
629
636
}
630
- property = ( (Component ) property .getValue () ).getProperty ( element );
631
637
}
638
+ return property ;
632
639
}
633
640
}
634
641
catch ( MappingException ee ) {
635
642
return null ;
636
643
}
637
644
}
638
- return property ;
639
645
}
640
646
641
647
/**
642
648
* Retrieve the property by path in a recursive way
643
649
*/
644
650
public static Property findPropertyByName (Component component , String propertyName ) {
645
- Property property = null ;
646
651
try {
647
652
if ( isEmpty ( propertyName ) ) {
648
653
// Do not expect to use a primary key for this case
649
654
return null ;
650
655
}
651
656
else {
657
+ Property property = null ;
652
658
final var tokens = new StringTokenizer ( propertyName , "." , false );
653
659
while ( tokens .hasMoreTokens () ) {
654
660
final String element = tokens .nextToken ();
655
661
if ( property == null ) {
656
662
property = component .getProperty ( element );
657
663
}
664
+ else if ( property .isComposite () ) {
665
+ final var value = (Component ) property .getValue ();
666
+ property = value .getProperty ( element );
667
+ }
658
668
else {
659
- if ( !property .isComposite () ) {
660
- return null ;
661
- }
662
- property = ( (Component ) property .getValue () ).getProperty ( element );
669
+ return null ;
663
670
}
664
671
}
672
+ return property ;
665
673
}
666
674
}
667
675
catch (MappingException e ) {
@@ -670,25 +678,29 @@ public static Property findPropertyByName(Component component, String propertyNa
670
678
if ( component .getOwner ().getIdentifierMapper () == null ) {
671
679
return null ;
672
680
}
673
- final var tokens = new StringTokenizer ( propertyName , "." , false );
674
- while ( tokens .hasMoreTokens () ) {
675
- final String element = tokens .nextToken ();
676
- if ( property == null ) {
677
- property = component .getOwner ().getIdentifierMapper ().getProperty ( element );
678
- }
679
- else {
680
- if ( !property .isComposite () ) {
681
+ else {
682
+ Property property = null ;
683
+ final var tokens = new StringTokenizer ( propertyName , "." , false );
684
+ while ( tokens .hasMoreTokens () ) {
685
+ final String element = tokens .nextToken ();
686
+ if ( property == null ) {
687
+ property = component .getOwner ().getIdentifierMapper ().getProperty ( element );
688
+ }
689
+ else if ( property .isComposite () ) {
690
+ final var value = (Component ) property .getValue ();
691
+ property = value .getProperty ( element );
692
+ }
693
+ else {
681
694
return null ;
682
695
}
683
- property = ( (Component ) property .getValue () ).getProperty ( element );
684
696
}
697
+ return property ;
685
698
}
686
699
}
687
700
catch (MappingException ee ) {
688
701
return null ;
689
702
}
690
703
}
691
- return property ;
692
704
}
693
705
694
706
public static String getRelativePath (PropertyHolder propertyHolder , String propertyName ) {
0 commit comments