How? It uses information that you provide which Java class corresponds to which table, Hibernate style JPA ORM annotated classes, either in XML or as plain java classes with annotations (one class per table).
If you have a large database, with multitude of tables, you can use the Hibernate / JBoss reverse engineering tool to generate the mapping classes directly from the database structure. See this: https://eugencovaciq.wordpress.com/2016/02/01/hibernate-tool...
There are other tools that could help. Why OpenXava? Because it is very easy to customize the generated user interface and it is very flexible. You just add @view annotations to the classes that modify how the interface is generated. For example, when you need to drop out some attributes, or not show a link to another table, or when the table is used as a lookup for the foreign key in another table, you can configure how the lookup will look like in one situation, and how in another. You can reconfigure the layout of complicated forms for tables with many attributes, also using view annotations.
I am not involved with OpenXava, but have used it to make an administration interface for several apps. I have a maven script that can be run from the command line, that uses hibernate reverse engineering library to generate the mapping classes and i have the initial app in minutes.