Postgres - ERROR: 42601: cannot insert multiple commands into a prepared statement

551 views
Skip to first unread message

wibber

unread,
Feb 22, 2011, 3:39:02 PM2/22/11
to nhusers
NH-2267 updated NpgsqlDriver to use prepared statements.
Unfortunately, this means that I can't get the identity generator to
work. Anybody got a good work-around for this yet? I'm thinking
about extending the postgres dialect to use the "returning [id]". I'm
not sure where to get the "id" inside the IdentitySelectString method.

Exception:
NHibernate.Exceptions.GenericADOException: could not insert:
[Entity.Test][SQL: INSERT INTO public."Test" ("Name") VALUES (?);
select lastval()] ---> Npgsql.NpgsqlException: ERROR: 42601: cannot
insert multiple commands into a prepared statement

Mapping File (truncated):
<class name="Test,Entity2" table="`Test`" >
<id name="Id" column="`BigId`" unsaved-value="0">
<generator class="identity" />
</id>
<property column="`Name`" type="String" name="Name" />
</class>

Filip Zawada

unread,
Feb 22, 2011, 10:41:58 PM2/22/11
to nhu...@googlegroups.com, wibber
On 2011-02-22 21:39, wibber wrote:
> NH-2267 updated NpgsqlDriver to use prepared statements.
> Unfortunately, this means that I can't get the identity generator to
> work. Anybody got a good work-around for this yet? I'm thinking
> about extending the postgres dialect to use the "returning [id]". I'm
> not sure where to get the "id" inside the IdentitySelectString method.

As a work around: Consider using HiLo generator.
Unless for some reason you really have to use DB-generated keys, HiLo is
the best choice for integer PKs. You might want to stick with it even
after the issue gets resolved.

Filip Zawada

wibber

unread,
Feb 23, 2011, 8:27:49 AM2/23/11
to nhusers
Would love to, but DBAs won't budge. If someone can tell me how to
get the name of the identity column from inside the
IdentitySelectString method, then I can solve the identity problem.
That's the last piece of the puzzle and I'll have an updated Postgres
dialect that works.
Reply all
Reply to author
Forward
0 new messages