Hi @cchen.1
First, the SW4STM32 is no more supported for the new STM32MCUs, for that, it's grayed on CubeMX interface for the H7A.
For the second point, which is the disappearance of the line of code entered by you when re-generate the project, you are totally right, issue confirmed (and thanks for your explication which allowed me to reproduce the issue) and now it's fixed, the fix will be available in the next CubeMX release.
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Thanks for your contribution, Khouloud