在我的grails(1.3.7)应用程序中,我使用JDBC模板从CSV文件批量导入1000个记录(因为它比使用vanilla GORM/hibernate快得多,正如您所期望的那样).
例如
class Book {
String title
}
Run Code Online (Sandbox Code Playgroud)
和
// For each CSV record...
insertStatementList.add("insert into book (id, title) values (nextval('hibernate_sequence'), thetitle)")
...
JdbcTemplate bulkInsert = ...
bulkInsert.batchUpdate(insertStatementList)
Run Code Online (Sandbox Code Playgroud)
这种方法的问题是域类的更改(例如添加subject属性)需要更改域类和SQL插入语句.
由于GORM/hibernate堆栈最终必须从域类定义派生SQL,有没有办法访问此功能,以便我不必单独维护SQL insert语句?或者在伪代码中,类似于以下内容:
// would return something like:
// "insert into book (id, title) values (nextval('hibernate_sequence'), 'thetitle')"
def insertStatement = hibernate.getSqlInsertForClass(Book, book.properties)
Run Code Online (Sandbox Code Playgroud)