[ 
https://issues.apache.org/jira/browse/CAY-1576?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13045417#comment-13045417
 ] 

nico commented on CAY-1576:
---------------------------

Hi Andrus,
I see the SQL activity in the logs (output) and it get the first Id with 
"SELECT nextval('XXXXX')". That is what I tried to describe.
The generation of 20 Ids by Cayenne after the select on sequence in database is 
the default generation strategy by Cayenne.
But then I select "Database-generated" in the modeler, I intended that Cayenne 
let the database generate the keys.

You have to set also support generated keys on adapter with:
((PostgresAdapter)context.getParentDataDomain().getNode("someNodeYouCreatedWithModeler").getAdapter()).setSupportsGeneratedKeys(true);

to let the database generate all Ids.

But you cannot cast to PostgresAdapter without set in the Cayenne Modeler in 
the created node under the tab "adapter" the "custom adapter" to 
"org.apache.cayenne.dba.postgres.PostgresAdapter"

If you do that all, the generation of primary keys are made in the database 
with PostgreSql 9.

I hope that helps other users with the same problem.

regards

> PK Generation with "meaningful PK"
> ----------------------------------
>
>                 Key: CAY-1576
>                 URL: https://issues.apache.org/jira/browse/CAY-1576
>             Project: Cayenne
>          Issue Type: Task
>          Components: Database integration
>    Affects Versions: 3.1M1
>         Environment: Win7 with PostgreSQL 9
>            Reporter: nico
>              Labels: features
>
> I have a question about the primary generation.
> I generate all classes with the Cayenne Modeler from the database with 
> "meaningful PK" option, because I need the getId()-method from the entity, 
> which gives me the Pk from the database.
> I set the Pk Generation Stategy to Database-Generated in all DbEntities, 
> because I don't wan't to set the Pk by myself or by Cayenne, but by database.
> Now I have the situation that Cayenne fetch the first PK from DB by calling 
> the sequence in Db, then Cayenne increment the ID 20 times (on 20 inserts) 
> and send the IDs (PKs) to database, then cayenne call another time the 
> sequence for next Pk id and so on.
> But I don't want that cayenne send any generated PK Id to database and only 
> let the database generate the Ids. I think this is a result of the 
> "meaningful PK" setting.
> Is there any solution to get the database PK Id from a Object Entity (at best 
> with getId()-method) without a database call and let the database generate 
> the primary keys?
> I hope this is understandable.
> thanks in advance

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to