Re: Spinning up Cayenne in a unit test.
And while we are at it, I absolutely must plug a mention of Bootique 2.0 / JUnit 5 testing facilities :) https://bootique.io/docs/2.x/bootique-docs/#_testing https://bootique.io/docs/2.x/bootique-jdbc-docs/#jdbc-testing They are on a totally different level: * Support for Docker/Testcontainers, so you'd test against a real DB, not Derby or H2 * Liquibase migrations in tests, so you can use a real up-to-date schema * "Global" scope for test databases and "apps", so you can share them across test classes, improving performance * Improved "Table" API for datatsets preparation and data assertions Andrus > On Oct 29, 2020, at 8:48 AM, Andrus Adamchik wrote: > > You can still start a BQRuntime in tests, even if the module doesn't use > Bootique. Then you'd define a DataSource within BQRuntime, and > "bootique-cayenne" would create a DataNode for it automatically and > transparently. YMMV with older Bootique versions. E.g. Agrest (that has no > Bootique dependency itself) is using Bootique for tests. > > Andrus > >> On Oct 29, 2020, at 7:27 AM, Tony Giaccone wrote: >> >> This is what I have now for the spin up: >> >> runtime = ServerRuntime.builder() >> .addConfig("cayenne-PriceIncrease.xml") >> .addModule(binder -> { >> ServerModule.contributeProperties(binder) >> .put("cayenne.jdbc.driver", "org.h2.Driver") >> .put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); >> }) >> .build(); >> DataNode node = new DataNode("testNode"); >> runtime.getDataDomain().setDefaultNode(node); >> >> >> And now on commit changes I get this: >> >> >> Caused by: java.lang.NullPointerException >> at >> org.apache.cayenne.access.DataDomainInsertBucket.createPermIds(DataDomainInsertBucket.java:103) >> at >> org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:73) >> at >> org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78) >> at >> org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:185) >> at >> org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:143) >> >> >> >> On Wed, Oct 28, 2020 at 4:08 PM John Huss wrote: >> >>> You could add a node at runtime: >>> >>> DataNode node = *new* DataNode("node"); >>> >>> ... // configure node >>> >>> runtime.getDataDomain().addNode(node); >>> >>> runtime.getDataDomain().setDefaultNode(node); >>> >>> On Wed, Oct 28, 2020 at 2:52 PM Tony Giaccone wrote: >>> So I have a project which is running in Bootique, but the data model is used in several different apps. To facilitate this, we created a jar file that includes the generated classes, and the code and the cayenne-project.xml file in one jar file. The result of this is tests >>> run for this jar, don't have access to the bootique runtime, as they are part of a jar that's going to be included in other apps. We're using an older version of Bootique and so the version of Cayenne is 4.0.B2 The cayenne project, only has a datamap there is no datanode defined in >>> the xml. So I'm trying to spin up a cayenne runtime, using this code. runtime = ServerRuntime.builder() .addConfig("cayenne-CohortManager.xml") .addModule(binder -> { ServerModule.contributeProperties(binder) .put("cayenne.jdbc.driver", "org.h2.Driver") .put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); }) .build(); The problem is that later, when I try to commit changes, I get this >>> error: org.apache.cayenne.CayenneRuntimeException: [v.4.0.B2 Sep 26 2017 10:05:06] No DataNode configured for DataMap 'datamap' and no default DataNode set I'm successfully able to run other tests, because they never do a commitobjects. Any suggestions on how to resolve my problem. >>> >
Re: Spinning up Cayenne in a unit test.
You can still start a BQRuntime in tests, even if the module doesn't use Bootique. Then you'd define a DataSource within BQRuntime, and "bootique-cayenne" would create a DataNode for it automatically and transparently. YMMV with older Bootique versions. E.g. Agrest (that has no Bootique dependency itself) is using Bootique for tests. Andrus > On Oct 29, 2020, at 7:27 AM, Tony Giaccone wrote: > > This is what I have now for the spin up: > > runtime = ServerRuntime.builder() >.addConfig("cayenne-PriceIncrease.xml") >.addModule(binder -> { >ServerModule.contributeProperties(binder) >.put("cayenne.jdbc.driver", "org.h2.Driver") >.put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); >}) >.build(); > DataNode node = new DataNode("testNode"); > runtime.getDataDomain().setDefaultNode(node); > > > And now on commit changes I get this: > > > Caused by: java.lang.NullPointerException > at > org.apache.cayenne.access.DataDomainInsertBucket.createPermIds(DataDomainInsertBucket.java:103) > at > org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:73) > at > org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:78) > at > org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:185) > at > org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:143) > > > > On Wed, Oct 28, 2020 at 4:08 PM John Huss wrote: > >> You could add a node at runtime: >> >> DataNode node = *new* DataNode("node"); >> >> ... // configure node >> >> runtime.getDataDomain().addNode(node); >> >> runtime.getDataDomain().setDefaultNode(node); >> >> On Wed, Oct 28, 2020 at 2:52 PM Tony Giaccone wrote: >> >>> So I have a project which is running in Bootique, but the data model is >>> used in several different apps. To facilitate this, we created a jar file >>> that includes the generated classes, and the code and the >>> cayenne-project.xml file in one jar file. The result of this is tests >> run >>> for this jar, don't have access to the bootique runtime, as they are part >>> of a jar that's going to be included in other apps. >>> >>> We're using an older version of Bootique and so the version of Cayenne is >>> 4.0.B2 >>> >>> The cayenne project, only has a datamap there is no datanode defined in >> the >>> xml. >>> >>> So I'm trying to spin up a cayenne runtime, using this code. >>> >>> runtime = ServerRuntime.builder() >>>.addConfig("cayenne-CohortManager.xml") >>>.addModule(binder -> { >>>ServerModule.contributeProperties(binder) >>>.put("cayenne.jdbc.driver", "org.h2.Driver") >>>.put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); >>>}) >>>.build(); >>> >>> >>> The problem is that later, when I try to commit changes, I get this >> error: >>> >>> org.apache.cayenne.CayenneRuntimeException: [v.4.0.B2 Sep 26 2017 >>> 10:05:06] No DataNode configured for DataMap 'datamap' and no default >>> DataNode set >>> >>> I'm successfully able to run other tests, because they never do a >>> commitobjects. >>> >>> >>> Any suggestions on how to resolve my problem. >>> >>
Re: MariaDB column with auto increment
ok, thx for the hint, I had to invalidate also object B, then the row got fetched again :-) Am Mi., 28. Okt. 2020 um 15:49 Uhr schrieb John Huss : > I'd turn on SQL logging and check that it is refetching the row via SQL. > Also query the DB to verify the value is set there. > > log4j.logger.org.apache.cayenne.log.JdbcEventLogger = INFO > > On Wed, Oct 28, 2020 at 2:35 AM Markus Reich > wrote: > > > Hi, > > > > I'm using Cayenne 4.1. > > I have an an object A with an one to one relation to another object B, > > in object B I got an column with an autoincrement field (no PK). > > Now when I create an new object A / B the value of the column stays at 0. > > I tried to refresh with object contexts invalidateObjects method and > with a > > RefreshQuery but it stays 0? > > > > regards > > > > -- > > *Markus Reich* > > Waldweg 62 > > 6393 St. Ulrich am Pillersee > > www.markusreich.at / www.meeximum.at > > markus.re...@markusreich.at > > > -- *Markus Reich* Waldweg 62 6393 St. Ulrich am Pillersee www.markusreich.at / www.meeximum.at markus.re...@markusreich.at
Re: Spinning up Cayenne in a unit test.
You could add a node at runtime: DataNode node = *new* DataNode("node"); ... // configure node runtime.getDataDomain().addNode(node); runtime.getDataDomain().setDefaultNode(node); On Wed, Oct 28, 2020 at 2:52 PM Tony Giaccone wrote: > So I have a project which is running in Bootique, but the data model is > used in several different apps. To facilitate this, we created a jar file > that includes the generated classes, and the code and the > cayenne-project.xml file in one jar file. The result of this is tests run > for this jar, don't have access to the bootique runtime, as they are part > of a jar that's going to be included in other apps. > > We're using an older version of Bootique and so the version of Cayenne is > 4.0.B2 > > The cayenne project, only has a datamap there is no datanode defined in the > xml. > > So I'm trying to spin up a cayenne runtime, using this code. > > runtime = ServerRuntime.builder() > .addConfig("cayenne-CohortManager.xml") > .addModule(binder -> { > ServerModule.contributeProperties(binder) > .put("cayenne.jdbc.driver", "org.h2.Driver") > .put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); > }) > .build(); > > > The problem is that later, when I try to commit changes, I get this error: > > org.apache.cayenne.CayenneRuntimeException: [v.4.0.B2 Sep 26 2017 > 10:05:06] No DataNode configured for DataMap 'datamap' and no default > DataNode set > > I'm successfully able to run other tests, because they never do a > commitobjects. > > > Any suggestions on how to resolve my problem. >
Spinning up Cayenne in a unit test.
So I have a project which is running in Bootique, but the data model is used in several different apps. To facilitate this, we created a jar file that includes the generated classes, and the code and the cayenne-project.xml file in one jar file. The result of this is tests run for this jar, don't have access to the bootique runtime, as they are part of a jar that's going to be included in other apps. We're using an older version of Bootique and so the version of Cayenne is 4.0.B2 The cayenne project, only has a datamap there is no datanode defined in the xml. So I'm trying to spin up a cayenne runtime, using this code. runtime = ServerRuntime.builder() .addConfig("cayenne-CohortManager.xml") .addModule(binder -> { ServerModule.contributeProperties(binder) .put("cayenne.jdbc.driver", "org.h2.Driver") .put("cayenne.jdbc.url", "jdbc:h2:mem:CohortDB"); }) .build(); The problem is that later, when I try to commit changes, I get this error: org.apache.cayenne.CayenneRuntimeException: [v.4.0.B2 Sep 26 2017 10:05:06] No DataNode configured for DataMap 'datamap' and no default DataNode set I'm successfully able to run other tests, because they never do a commitobjects. Any suggestions on how to resolve my problem.
Re: MariaDB column with auto increment
I'd turn on SQL logging and check that it is refetching the row via SQL. Also query the DB to verify the value is set there. log4j.logger.org.apache.cayenne.log.JdbcEventLogger = INFO On Wed, Oct 28, 2020 at 2:35 AM Markus Reich wrote: > Hi, > > I'm using Cayenne 4.1. > I have an an object A with an one to one relation to another object B, > in object B I got an column with an autoincrement field (no PK). > Now when I create an new object A / B the value of the column stays at 0. > I tried to refresh with object contexts invalidateObjects method and with a > RefreshQuery but it stays 0? > > regards > > -- > *Markus Reich* > Waldweg 62 > 6393 St. Ulrich am Pillersee > www.markusreich.at / www.meeximum.at > markus.re...@markusreich.at >
MariaDB column with auto increment
Hi, I'm using Cayenne 4.1. I have an an object A with an one to one relation to another object B, in object B I got an column with an autoincrement field (no PK). Now when I create an new object A / B the value of the column stays at 0. I tried to refresh with object contexts invalidateObjects method and with a RefreshQuery but it stays 0? regards -- *Markus Reich* Waldweg 62 6393 St. Ulrich am Pillersee www.markusreich.at / www.meeximum.at markus.re...@markusreich.at