users@jersey.java.net

How to insert using a default pk assignment?

From: Marsh Eric <emarsh_at_mac.com>
Date: Tue, 20 Jan 2009 16:26:51 -0600

Hi Paul,
I was under the impression that Jersey was part of the layer that
formatted the HTTP reads and writes, residing between the HTTP and the
persistence/database layer and had some effect on what is written to
the database. So now that I'm aware that there is a distinction I
guess that my issue would be the netbeans generated code. I thought
that was part of the Jersey project. If I'm sending email to the wrong
group then can you point me to the right people?
Regarding the problem that I'm experiencing, I had previously removed
the put/get methods along with the field descriptor from one of the
generated entity files for a column that I didn't want to have
INSERTED into the database. The effect was that all references to that
column disappeared from the INSERT statement. However I can't do the
same with the primary key because of the other dependencies on it,
though again I simply don't want it to be INSERTED.
Here's the JSON text that I sent via an HTTP POST which is responsible
for the exception below. Note that at the time the date formatter
wasn't working right which is why the date was insert into the
database as a NULL.
However, beyond that it looks like I'm getting close to having this
thing working after a period of frustration. Thanks for the help.
BTW, any what code might be causing the duplicate records that are
appearing from a GET?
{"accuracy":"17",
"mykey":{"@uri":"http://192.168.0.3:8080/HereIAmDB/resources/peoples/emarsh/
"},
"@uri":"http://192.168.0.3:8080/HereIAmDB/resources/mylocations/",
"longitude":"-97.62597",
"time":"2009-19-19T11:19:53-06:00" ,
"latitude":"29.92574",
"peoplecollection":{"people":[{"@uri":"http://192.168.0.3:8080/HereIAmDB/resources/peoples/
"}],
"uri":"http://192.168.0.3:8080/HereIAmDB/resources/peoples/"}}

--------
Hi Eric,

Jersey does not do anything with databases. Are you referring to
NetBeans generated code?

Could you describe the HTTP operation you performed and with what data?

Paul.


On Jan 20, 2009, at 7:01 PM, Marsh Eric wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>