Sorry, this fell through the cracks. Yeah, there's API to reset PK generator 
(unfortunately the only piece of the stack that is not managed via DI):

  ServerRuntime runtime = ...;
  runtime.getDataDomain().getDataNode("mynode").getAdapter().setPkGenerator(new 
JdbcPkGenerator());

Andrus

> On Mar 30, 2021, at 7:56 AM, Gilberto Caetano de Andrade 
> <gilbert...@gmail.com> wrote:
> 
> 
> 
> On 2021/03/30 06:10:45, Andrus Adamchik <aadamc...@gmail.com> wrote: 
>> Yeah, schema handling for PK support objects is limited. So you adding it 
>> manually to the script was a good idea.
>> 
>>>> I choose JdbcAdapter because I want the Cayenne-Generated PK option
>> 
>> From the exception stack trace, your DB is "h2", so try using the H2 Adapter 
>> (org.apache.cayenne.dba.h2.H2Adapter) when doing DB generation.
>> 
> Andrus, as I've said I don't want the database specific pk management, I do 
> want  the cayenne one since I think is the easiest one to add new table.
> 
> Today, testing it again it throw the h2 sequence exception:
> 
> Caused by: org.apache.cayenne.CayenneRuntimeException: [v.4.1 Jul 14 2020 
> 10:26:08] Commit Exception
>       at 
> org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:774)
>       at 
> org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:691)
>       at 
> com.gilbertoca.corretagem.dao.NotaCayenneDao.create(NotaCayenneDao.java:59)
>       at 
> com.gilbertoca.corretagem.view.NotaController.salvar(NotaController.java:159)
>       ... 58 more
> Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Sequence "PK_NOTA" not 
> found; SQL statement:
> SELECT NEXT VALUE FOR corretagem.pk_nota [90036-200]
>       at org.h2.message.DbException.getJdbcSQLException(DbException.java:576)
>       at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
>       at org.h2.message.DbException.get(DbException.java:205)
>       at org.h2.message.DbException.get(DbException.java:181)
>       at org.h2.schema.Schema.getSequence(Schema.java:585)
> 
> Can I set it programmatically, the Cayenne one?
> Thank you!
> 
> Gilberto
> 
> 
>> 
>> 
>>> On Mar 29, 2021, at 10:12 PM, Gilberto Caetano de Andrade 
>>> <gilbert...@gmail.com> wrote:
>>> 
>>> The image: 
>>> https://www.dropbox.com/s/t3swzbn4fzrfyqb/CayenneModelerPkGeneration.png?dl=0
>>> 
>>> On 2021/03/29 19:08:11, Gilberto Caetano de Andrade <gilbert...@gmail.com> 
>>> wrote: 
>>>> Hello,
>>>> 
>>>> Finally I could start personal project which I can use cayenne again after 
>>>> good time. I'm using the version 4.1 and every table/class were setup 
>>>> through Cayenne-Modeler, the PK generation strategy is the default one. At 
>>>> the db generate schema dialog I choose JdbcAdapter because I want the 
>>>> Cayenne-Generated PK option (image)
>>>> As you can see in the image, Cayenne-Modeler doesn't create the sql 
>>>> correctly for table auto_pk_support, missis the schema.
>>>> I discovery this on the first time I've tried to insert in the table and 
>>>> Cayenne gave an exception about sequence PK_NOTA existence, despite 
>>>> choosing the default option.
>>>> After that I've copied that generated sql, put the schema (corretagem) and 
>>>> update the database. I'm stoped again, on insert, this time because 
>>>> Cayenne have not set the ID, throuwing a commit exception:
>>>> 
>>>> Caused by: java.lang.reflect.InvocationTargetException
>>>>    at 
>>>> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
>>>> Method)
>>>>    at 
>>>> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>>>    at 
>>>> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>>>>    at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
>>>>    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>>>>    at 
>>>> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>>>>    at 
>>>> javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
>>>>    at 
>>>> javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
>>>>    at 
>>>> javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1782)
>>>>    ... 47 more
>>>> Caused by: org.apache.cayenne.CayenneRuntimeException: [v.4.1 Jul 14 2020 
>>>> 10:26:08] Commit Exception
>>>>    at 
>>>> org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:774)
>>>>    at 
>>>> org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:691)
>>>>    at 
>>>> com.gilbertoca.corretagem.dao.NotaCayenneDao.create(NotaCayenneDao.java:59)
>>>>    at 
>>>> com.gilbertoca.corretagem.view.NotaController.salvar(NotaController.java:142)
>>>>    ... 58 more
>>>> Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL 
>>>> not allowed for column "ID"; SQL statement:
>>>> INSERT INTO corretagem.nota (agente_id, corretagem, dt_pregao, 
>>>> emolumentos, horario, irpf_operacao_base, iss, nr_nota, tx_ana, 
>>>> tx_liquidacao, tx_registro, tx_termo_opcao_futuro) VALUES (?, ?, ?, ?, ?, 
>>>> ?, ?, ?, ?, ?, ?, ?) [23502-200]
>>>>    at org.h2.message.DbException.getJdbcSQLException(DbException.java:459)
>>>>    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
>>>>    at org.h2.message.DbException.get(DbException.java:205)
>>>>    at org.h2.message.DbException.get(DbException.java:181)
>>>>    at org.h2.table.Column.validateConvertUpdateSequence(Column.java:374)
>>>>    at org.h2.table.Table.validateConvertUpdateSequence(Table.java:845)
>>>>    at org.h2.command.dml.Insert.insertRows(Insert.java:187)
>>>>    at org.h2.command.dml.Insert.update(Insert.java:151)
>>>>    at 
>>>> org.h2.command.CommandContainer.executeUpdateWithGeneratedKeys(CommandContainer.java:272)
>>>>    at org.h2.command.CommandContainer.update(CommandContainer.java:191)
>>>>    at org.h2.command.Command.executeUpdate(Command.java:251)
>>>>    at 
>>>> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:191)
>>>>    at 
>>>> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:152)
>>>>    at 
>>>> org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:171)
>>>>    at 
>>>> org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:90)
>>>>    at 
>>>> org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
>>>>    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)
>>>>    at 
>>>> org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:233)
>>>>    at 
>>>> org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:153)
>>>>    at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:624)
>>>>    at 
>>>> org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:594)
>>>>    at 
>>>> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:822)
>>>>    at 
>>>> org.apache.cayenne.tx.TransactionFilter.lambda$onSync$0(TransactionFilter.java:61)
>>>>    at 
>>>> org.apache.cayenne.tx.DefaultTransactionManager$BaseTransactionHandler.performInTransaction(DefaultTransactionManager.java:183)
>>>>    at 
>>>> org.apache.cayenne.tx.DefaultTransactionManager$BaseTransactionHandler.performInNewTransaction(DefaultTransactionManager.java:155)
>>>>    at 
>>>> org.apache.cayenne.tx.DefaultTransactionManager$NestedTransactionHandler.handle(DefaultTransactionManager.java:98)
>>>>    at 
>>>> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:65)
>>>>    at 
>>>> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:43)
>>>>    at 
>>>> org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:61)
>>>>    at 
>>>> org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:821)
>>>>    at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:581)
>>>>    at 
>>>> org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:742)
>>>>    ... 61 more
>>>> 
>>>> So, I'm here looking for help.
>>>> Regards,
>>>> Gilberto
>>>> 
>> 
>> 

Reply via email to