All i want is to execute the following SQL on my PostgreSQL server after my Hibernate SessionFactory has been initialized:
CREATE SCHEMA IF NOT EXISTS "fooschema" AUTHORIZATION "foouser";
Currently I am using the following routine:
Session s = factory.withOptions().openSession();
SQLQuery query = s.createSQLQuery(sql);
int res = query.executeUpdate();
// res is 0 and the schema has NOT been created
s.flush();
s.disconnect();
s.close();
The connected user has the permissions to chreate new schemata. So this is a simple question: What am i doing wrong?
Attachments:
Turning hibernate show_sql on prints the following:
Hibernate:
CREATE SCHEMA IF NOT EXISTS "fooschema" AUTHORIZATION "foouser";
Try setting property
<property name="hbm2ddl.auto" value="create"/>
in hibernate config
The solution for my problem (Thanks to @a_horse_with_no_name)
Session s = factory.withOptions().openSession();
Transaction tx = s.beginTransaction();
SQLQuery query = s.createSQLQuery(sql);
int res = query.executeUpdate();
tx.commit();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.