Hi
Check the below forum answer
https://community.mendix.com/link/space/app-development/questions/92126
You will need to do an XPath Retrieve for Entity2 in your Java Action. The Mendix documentation gives a worked example of a similar use case to yours showing how to retrieve over the relationship between the two entities via XPath.
https://docs.mendix.com/refguide/extending-your-application-with-custom-java/
Good luck!