Re: Cayenne-Generated PK (NULL not allowed for column "ID")
On 2021/03/30 06:10:45, Andrus Adamchik 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 > > wrote: > > > > The image: > > https://www.dropbox.com/s/t3swzbn4fzrfyqb/CayenneModelerPkGeneration.png?dl=0 > > > > On 2021/03/29 19:08:11, Gilberto Caetano de Andrade > > 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) > >>
Re: Cayenne-Generated PK (NULL not allowed for column "ID")
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 > On Mar 29, 2021, at 10:12 PM, Gilberto Caetano de Andrade > wrote: > > The image: > https://www.dropbox.com/s/t3swzbn4fzrfyqb/CayenneModelerPkGeneration.png?dl=0 > > On 2021/03/29 19:08:11, Gilberto Caetano de Andrade > 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 >>