I am new to this this forum and rather new to Hibernate ORM, so I am unsure if this belongs, but I’ll try anyways: Currently I am putting together a very HelloWorld-ish application.
For this I use Java 11 OpenJDK and OpenJ9, Hibernate 5.4 and IBM Db2 11 for Windows.
The domain model consists of only one class and so only one table is to be generated. All I want for now, is to have my table generated and to have a few simple entites written into it. As you can see below, the hbm2ddl.auto property is set to create.
Now the problem is that for the first time I run my program, I receive an SQL -204 because a DROP TABLE statement is issued, but there is no such table yet. Subsequent runs do not experience this error as the table now exists.
I tested the same code with the hbm2ddl.auto property also set to true with Postgre and it worked perfectly fine from the start as with the PostgreSQLDialect there is an IF EXISTS clause generated fpr the DROP TABLE command.
Checking the code on Github I could quickly see that for Postgre the dialect’s supportsIfExistsBeforeTableName() method returns true since PostgreSQL82Dialect. For the Db2Dialect supportsIfExistsAfterTableName() could (and should ?) return true - but it does not. Would somebody please be so kind as to explain why? Am I missing something? Is it for backwards compatibility?
Can I make Hibernate generate an IF EXISTS clause anyways?
My hibernate.cfg.xml looks like this:
<?xml version = "1.0" encoding = "utf-8"?> <hibernate-configuration> <session-factory> <property name = "hibernate.dialect">org.hibernate.dialect.DB2Dialect</property> <property name = "hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property> <property name = "hibernate.connection.url">jdbc:db2://localhost:50000/HIBERN8</property> <property name = "hibernate.connection.username">myDb2User</property> <property name = "hibernate.connection.password">myDb2Pw</property> <property name="hbm2ddl.auto">create</property> <property name="show_sql">true</property> </session-factory> </hibernate-configuration>
Thank you very much for your answers!