Search code examples
javahibernatedb2zos

Hibernate and DB2 on z/OS - auto-create table


my current problem is that I want to use Hibernate on DB2 to do this nice ORM-stuff and it somehow works, but not really like I want it to .. The core of the problem is that I can only connect to a DB2-subsystem via JDBC and have to specify the database in which to create the table in the SQL-query, which seems to be missing in Hibernate - since the table is created, but in some kind of auto-created database. Is there some way to append a " in database [...]" to the DDL or sth. similar?

Thanks.


Solution

  • I found a nice solution by extending the DB2Dialect:

    public class DB2Dialect extends org.hibernate.dialect.DB2400Dialect {
        public static String db;
    
        @Override
        public String getTableTypeString() {
            return " IN DATABASE " + db;
        }
    }
    

    And since the comment for this function implies that it's designated to a MySQL feature, I guess it's fine for the moment.