我想使用createNativeQuery
創建多個表,但它會導致只創建第一個表的hibernate。如果我將粘貼SQL複製到SQL編輯器,它工作正常。這裏是我的代碼:爲什麼hibernate只創建第一個表?
String sql = "CREATE TABLE \"languages\"("+
"language_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
"language_name VARCHAR(50) NOT NULL,"+
"language_code VARCHAR(3) NOT NULL);"+
"CREATE TABLE \"accountant\"("+
"accountant_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
"name VARCHAR(50) NOT NULL,"+
"surname VARCHAR(50) NOT NULL,"+
"mail VARCHAR(100) NOT NULL,"+
"avatar VARCHAR(150),"+
"phone VARCHAR(16),"+
"interface_lang_id INTEGER NOT NULL,"+
"FOREIGN KEY(interface_lang_id) REFERENCES languages(language_id) ON DELETE RESTRICT);"+
"CREATE TABLE \"currency\"("+
"currency_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
"name VARCHAR(25) NOT NULL,"+
"symbol VARCHAR(5) NOT NULL);";
session.createNativeQuery(sql).executeUpdate();
我不確定你可以使用JPA原生查詢執行DDL(CREATE,ALTER,DROP等..),但只有DML(SELECT,UPDATE,DELETE,INSERT等)。對於DDL操作,您應該使用' create '按照Sangram Badi建議的 –
實際上,可以將DDL用於JPA本機查詢,因此Sangram Badi解決方案應該可以工作。 –
@Aassass,是的,我認爲我的解決方案可能工作。 –