Thank you Ankit kumar, I did not know you could do that this way with Hibernate.
Thank you life888888, I haven't heard of MyBatis Generator, I'll have a look!
zwitserloot, thanks for your detailed answer. I appreciate the time you took to write it, and I want to clarify my perspective because I think my original question may have given the wrong impression.
I definitely do not find SQL or databases scary. My background is in Business Data Processing studies, where we were very data-oriented. We often worked in C#, using ER diagrams, forward engineering, and WPF projects. We generated models from the database, but we never treated those generated classes as the application itself. With MVVM and layered designs, we always separated business logic, view models, domain behavior, and everything else.
Later, in my professional work with Java, I mostly used Code First approaches with Quarkus, Spring Boot, and Hibernate. So I have experience on both sides, Code First and Database First.
Recently, I talked with an old classmate who builds ERP modules. His company still uses a Database First approach because it helps them design clean data models from the start, which works well for modular ERP systems. That made me think about the advantages and disadvantages I have seen myself. Code First usually lets you move faster at the beginning, but I often ended up refactoring a lot when the data structure evolved. Database First is slower at the start, but since I think visually, working with ER diagrams makes it easier for me to design something stable and maintainable.
For personal projects, I want to try combining both ideas. I would design the schema first, maybe generate simple models, and then build a proper hexagonal architecture. Domain objects would stay independent from the persistence layer. For example, a User domain object may have behaviors that are not stored in the database and that are unrelated to table fields.
My question was not about treating database tables as domain objects. I agree with you on that. I was only asking whether Java has something similar to what I used in C#. I have already done Database First there, but never in Java.
Both philosophies have their pros and cons.
By the way, just to be sure before answering you, I tested MySQL Workbench to check that when you modify tables with forward engineering, it doesn’t erase the existing tables and keeps everything. It works. I liked that approach because it really lets you visualize your database (yes, I know UML is not often apprieciated in the working world, but I still like it maybe that’s my old student side showing XD).
About database engine migration, I might have misunderstood your point. From my experience, switching from MySQL to PostgreSQL is a major change no matter which approach you use. And version upgrades depend heavily on the system’s architecture, not just the ORM.
Thanks again for your answer and your perspective. And if I misunderstood anything you wrote or you want to add something, feel free to let me know.