开发者

HQL Insert Query in Grails

I want to write an insert query in Grails. I have tried all possible combinations but cant get the syntax correct. Can anybody please help?

class Person {
    int age
    String name
}

i tried the following:

Person.executeUpdate("insert into Person  values (20,"ABC")")

p.s.:Please do not men开发者_运维问答tion using save()


Execute a native query:

def sql = new Sql(sessionFactory.currentSession.connection())
sql.execute("insert into person values(?,?)", ["foo", "bar"])

note that person is the actual table name.


It doesn't look possible. See http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html#batch-direct and note that it says "Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form." So you can insert as a select from one or more other tables, but can't insert directly like you would with save().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜