You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Rashid Khan <ra...@gmail.com> on 2006/10/19 11:17:02 UTC

Cayenne not taking account of PKs created by external SQL script

Hi all,

I am using cayenne-1.2. I have noticed that when I add a new record manually
(using sql script) in my database, cayenne does not take into account the
primary key of that record. Let me explain this by giving an example.

Let's say I _manually_ created the following record in my report table which
has two columns: report_id and name.

report_id    |    name
----------------  --------------
200           |    report1

Now when I use cayenne to insert a new report, I get an exception saying
"duplicate key".

Is there any way I can make cayenne aware of the records that have been
created manually? Or better yet, can I get rid of Cayenne Auto PK support
completely?

Any ideas will be appreciated.

Thanks,

Rashid

Re: Cayenne not taking account of PKs created by external SQL script

Posted by Kevin Menard <km...@servprise.com>.
My only addition to this is that you may need to limit the number of 
keys Cayenne caches (by default: 20) to just one.  Otherwise, Cayenne 
will assume that block of IDs are valid for use.

-- 
Kevin Menard
Servprise International, Inc.
"Remote reboot without pulling the plug" -- http://www.servprise.com 



Tore Halset wrote:
> On Oct 19, 2006, at 11:17, Rashid Khan wrote:
>
>> Is there any way I can make cayenne aware of the records that have been
>> created manually?
>
> You can update AUTO_PK_SUPPORT or pk sequence created by cayenne. You 
> should update this before inserting to grap a block of primary key 
> values just as cayenne does.
>
> Or you could use cayenne to "manually insert" that record.
>
>> Or better yet, can I get rid of Cayenne Auto PK support completely?
>
> Take a look at database generated keys. Not all databases and jdbc- 
> driver support them.
>
>  - Tore.
>

Re: Cayenne not taking account of PKs created by external SQL script

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Oct 19, 2006, at 11:17, Rashid Khan wrote:

> Is there any way I can make cayenne aware of the records that have  
> been
> created manually?

You can update AUTO_PK_SUPPORT or pk sequence created by cayenne. You  
should update this before inserting to grap a block of primary key  
values just as cayenne does.

Or you could use cayenne to "manually insert" that record.

> Or better yet, can I get rid of Cayenne Auto PK support completely?

Take a look at database generated keys. Not all databases and jdbc- 
driver support them.

  - Tore.