I must generate custom domain types for the web framework. We've the engineering part where we are able to model domain types that will then produced into Java code with JPA Annotations.

I considered a corrected approach, where one can specify the database schema and obtain the produced models that are now compatible vice-versa.

It is possible to framework where one can intercept the generation, something similar to the Hibernate POJO generation. It ought to be easy to access the tables, obtain the column names, types, relations, primary secrets, easily via Java. The relaxation would depend on me to create the right models.

Any suggestions how to begin?

Tables, column names, indexes and so forth could be acquired using standard jdbc classes, see DatabaseMetaData. Here's some code that may enable you to get began:

static void dumpResultSet(ResultSet rs) throws SQLException {
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    PrintStream out = System.out;
    while (rs.next()) {
        out.print("{\n");
        for (int i=1; i<=columnCount; i++) {
            out.print("    ");
            out.print(md.getColumnLabel(i));
            out.print(": ");
            out.print(rs.getObject(i));

            if (i<columnCount-1) {
                out.print(", ");
            }
            out.print("\n");
        }
        out.print("}\n");
    }
}

Connection con = ...;
DatabaseMetaData md = con.getMetaData();

dumpResultSet(md.getTables(null, null, null, new String[]{"TABLE", "VIEW"}));
dumpResultSet(md.getColumns(null, null, "TABLE_NAME", null));
dumpResultSet(md.getExportedKeys(null, null, "TABLE_NAME"));
dumpResultSet(md.getImportedKeys(null, null, "TABLE_NAME"));
dumpResultSet(md.getPrimaryKeys(null, null, "TABLE_NAME"));
dumpResultSet(md.getIndexInfo(null, null, "TABLE_NAME", false, true));

I'd use something similar to codesmith. It's language agnostic and may review a database to produce the models you would like. http://www.codesmithtools.com/

Before any ORMs arrived on the scene for android I made use of it to create my models for sqlite. It labored very nicely.

I've designed a tool just for your: DB Importer. It creates JPA classes from the database schema. The code generation is extremely configurable having a Groovy script. The Groovy syntax utilized in this script is like Java.