开发者

HQL Insert Query in Grails

开发者 https://www.devze.com 2022-12-28 20:29 出处:网络
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?

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

精彩评论

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