@@ -583,15 +583,15 @@ private static void matchColumnsByProperty(Property property, Map<Column, Set<Pr
583583 * If propertyName is null or empty, the IdentifierProperty is returned
584584 */
585585 public static Property findPropertyByName (PersistentClass associatedClass , String propertyName ) {
586- Property property = null ;
587586 final Property idProperty = associatedClass .getIdentifierProperty ();
588587 final String idName = idProperty == null ? null : idProperty .getName ();
589588 try {
590589 if ( isEmpty ( propertyName ) || propertyName .equals ( idName ) ) {
591590 //default to id
592- property = idProperty ;
591+ return idProperty ;
593592 }
594593 else {
594+ Property property = null ;
595595 if ( propertyName .indexOf ( idName + "." ) == 0 ) {
596596 property = idProperty ;
597597 propertyName = propertyName .substring ( idName .length () + 1 );
@@ -602,13 +602,15 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
602602 if ( property == null ) {
603603 property = associatedClass .getProperty ( element );
604604 }
605+ else if ( property .isComposite () ) {
606+ final var value = (Component ) property .getValue ();
607+ property = value .getProperty ( element );
608+ }
605609 else {
606- if ( !property .isComposite () ) {
607- return null ;
608- }
609- property = ( (Component ) property .getValue () ).getProperty ( element );
610+ return null ;
610611 }
611612 }
613+ return property ;
612614 }
613615 }
614616 catch ( MappingException e ) {
@@ -617,51 +619,57 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
617619 if ( associatedClass .getIdentifierMapper () == null ) {
618620 return null ;
619621 }
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 {
628635 return null ;
629636 }
630- property = ( (Component ) property .getValue () ).getProperty ( element );
631637 }
638+ return property ;
632639 }
633640 }
634641 catch ( MappingException ee ) {
635642 return null ;
636643 }
637644 }
638- return property ;
639645 }
640646
641647 /**
642648 * Retrieve the property by path in a recursive way
643649 */
644650 public static Property findPropertyByName (Component component , String propertyName ) {
645- Property property = null ;
646651 try {
647652 if ( isEmpty ( propertyName ) ) {
648653 // Do not expect to use a primary key for this case
649654 return null ;
650655 }
651656 else {
657+ Property property = null ;
652658 final var tokens = new StringTokenizer ( propertyName , "." , false );
653659 while ( tokens .hasMoreTokens () ) {
654660 final String element = tokens .nextToken ();
655661 if ( property == null ) {
656662 property = component .getProperty ( element );
657663 }
664+ else if ( property .isComposite () ) {
665+ final var value = (Component ) property .getValue ();
666+ property = value .getProperty ( element );
667+ }
658668 else {
659- if ( !property .isComposite () ) {
660- return null ;
661- }
662- property = ( (Component ) property .getValue () ).getProperty ( element );
669+ return null ;
663670 }
664671 }
672+ return property ;
665673 }
666674 }
667675 catch (MappingException e ) {
@@ -670,25 +678,29 @@ public static Property findPropertyByName(Component component, String propertyNa
670678 if ( component .getOwner ().getIdentifierMapper () == null ) {
671679 return null ;
672680 }
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 {
681694 return null ;
682695 }
683- property = ( (Component ) property .getValue () ).getProperty ( element );
684696 }
697+ return property ;
685698 }
686699 }
687700 catch (MappingException ee ) {
688701 return null ;
689702 }
690703 }
691- return property ;
692704 }
693705
694706 public static String getRelativePath (PropertyHolder propertyHolder , String propertyName ) {
0 commit comments