users@jersey.java.net

How to insert using a default pk assignment?

From: Marsh Eric <emarsh_at_mac.com>
Date: Tue, 20 Jan 2009 12:01:56 -0600

Hello,

I'm working on inserting a new record that was created remotely and
then passed via RESTful services and inserted into a common database.
Because of the record's remote creation it does not know what primary
key will be used when it is inserted into the main database. The
database itself will generate the primary key's value.

The problem I'm experiencing is that when I pass a record to the local
server without a primary key value being passed a null value is being
generated for the primary key somewhere in the Jersey layers the
system is attempting to insert it. This is causing the following
exception:

Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build
b09d-fcs (12/06/2007))):
oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: null
value in column "pk" violates not-null constraint
Error Code: 0
Call: INSERT INTO mylocation (pk, accuracy, time, latitude, imat,
longitude, bindatakey, mykey) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
         bind => [null, 17, null, 29.92574, null, -97.62597, null, 1]
Query: InsertObjectQuery(hereiam.Mylocation[pk=null])

How can I prevent the system from attempting to insert a null value
(or for that matter any value) for the primary key? I've tried
changing the @Column value to "insertable = false" but that hasn't
worked.

Thanks,

Eric