How to set up an insert to a grails created file with next sequence number?
- by Jack BeNimble
I'm using a JMS queue to read from and insert data into a postgres table created by grails. The problem is obtaining the next sequence value. I thought I had found the solution with the following statement (by putting "DEFAULT" where the ID should go), but it's no longer working. I must have changed something, because I needed to recreate the table. What's the best way to get around this problem?
ps = c.prepareStatement("INSERT INTO xml_test (id, version, xml_text)
VALUES (DEFAULT, 0, ?)");
UPDATE:
In response to the suggested solution, I did the following:
Added this to the the domain:
class XmlTest {
String xmlText
static constraints = {
id generator:'sequence', params:[name:'xmltest_sequence']
}
}
And changed the insert statement to the following:
ps = c.prepareStatement("INSERT INTO xml_test (id, version, xml_text)
VALUES (nextval('xmltest_sequence'), 0, ?)");
However, when I run the statement, I get the following error:
[java] 1 org.postgresql.util.PSQLException: ERROR: relation "xmltest_sequence" does not exist
Any thoughts?