Graal (Native Image) with Cayenne
Hello; Has anybody here experimented with running an application using Cayenne with the GraalVM "native image" compiler? The resultant executable seems to be having a problem with the DI system at run time; probably because there's some reflection going on in there -- seems likely. Is there any documentation / guidance about how to start the `ServerRuntime` without the DI mechanism? Caused by: org.apache.cayenne.di.DIRuntimeException: No applicable constructor is found for constructor injection in class 'org.apache.cayenne.log.Slf4jJdbcEventLogger' at org.apache.cayenne.di.spi.ConstructorInjectingProvider.initConstructor(ConstructorInjectingProvider.java:103) ~[na:na] at org.apache.cayenne.di.spi.ConstructorInjectingProvider.(ConstructorInjectingProvider.java:42) ~[na:na] at org.apache.cayenne.di.spi.DefaultBindingBuilder.to(DefaultBindingBuilder.java:44) ~[na:na] at org.apache.cayenne.configuration.server.ServerModule.configure(ServerModule.java:349) ~[na:na] at org.apache.cayenne.di.spi.DefaultInjector.(DefaultInjector.java:68) ~[na:na] at org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:38) ~[na:na] at org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:46) ~[na:na] at org.apache.cayenne.configuration.CayenneRuntime.(CayenneRuntime.java:79) ~[haikudepotserver-webapp:4.1.1] at org.apache.cayenne.configuration.server.ServerRuntime.(ServerRuntime.java:75) ~[haikudepotserver-webapp:4.1.1] at org.apache.cayenne.configuration.server.ServerRuntimeBuilder.build(ServerRuntimeBuilder.java:207) ~[na:na] Regards. -- Andrew Lindesay
Re: Graal (Native Image) with Cayenne
Hi Andrew, I don't have first-hand experience, but Cayenne was reported to work with GraalVM. E.g.: https://lists.apache.org/list?user@cayenne.apache.org:2023-1:graalvm Andrus > On Apr 5, 2023, at 10:26 AM, Andrew Lindesay wrote: > > Hello; > > Has anybody here experimented with running an application using Cayenne with > the GraalVM "native image" compiler? The resultant executable seems to be > having a problem with the DI system at run time; probably because there's > some reflection going on in there -- seems likely. Is there any > documentation / guidance about how to start the `ServerRuntime` without the > DI mechanism? > > Caused by: org.apache.cayenne.di.DIRuntimeException: No applicable > constructor is found for constructor injection in class > 'org.apache.cayenne.log.Slf4jJdbcEventLogger' > at > org.apache.cayenne.di.spi.ConstructorInjectingProvider.initConstructor(ConstructorInjectingProvider.java:103) > ~[na:na] > at > org.apache.cayenne.di.spi.ConstructorInjectingProvider.(ConstructorInjectingProvider.java:42) > ~[na:na] > at > org.apache.cayenne.di.spi.DefaultBindingBuilder.to(DefaultBindingBuilder.java:44) > ~[na:na] > at > org.apache.cayenne.configuration.server.ServerModule.configure(ServerModule.java:349) > ~[na:na] > at > org.apache.cayenne.di.spi.DefaultInjector.(DefaultInjector.java:68) > ~[na:na] > at > org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:38) ~[na:na] > at > org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:46) ~[na:na] > at > org.apache.cayenne.configuration.CayenneRuntime.(CayenneRuntime.java:79) > ~[haikudepotserver-webapp:4.1.1] > at > org.apache.cayenne.configuration.server.ServerRuntime.(ServerRuntime.java:75) > ~[haikudepotserver-webapp:4.1.1] > at > org.apache.cayenne.configuration.server.ServerRuntimeBuilder.build(ServerRuntimeBuilder.java:207) > ~[na:na] > > Regards. > > -- > Andrew Lindesay
Re: Graal (Native Image) with Cayenne
Hi Andrus; Thanks for coming back to me. It seems that for my situation, I need to let the build tool know that each of the "injectable" classes should be allowed to be scanned for constructors in the build product by supplying the Graal build-tool with; ``` -H:ReflectionConfigurationFiles=/...path.../reflection.json ``` The snipped `reflection.json` file looks like; ``` [ { "name": "org.apache.cayenne.access.DataDomain", "queryAllDeclaredConstructors": true }, { "name": "org.apache.cayenne.access.dbsync.DefaultSchemaUpdateStrategyFactory", "queryAllDeclaredConstructors": true }, ... continued ] ``` There are entries for 117 classes. It seems this file can be supplied with the library jar in some way in order to instruct the Graal build tool. Maybe once I have this fully working I can add a PR for it to cover the known classes in the jar(s). Regards. -- Andrew Lindesay On Wed, 5 Apr 2023, at 20:31, Andrus Adamchik wrote: > Hi Andrew, > > I don't have first-hand experience, but Cayenne was reported to work > with GraalVM. E.g.: > https://lists.apache.org/list?user@cayenne.apache.org:2023-1:graalvm > > Andrus > > >> On Apr 5, 2023, at 10:26 AM, Andrew Lindesay wrote: >> >> Hello; >> >> Has anybody here experimented with running an application using Cayenne with >> the GraalVM "native image" compiler? The resultant executable seems to be >> having a problem with the DI system at run time; probably because there's >> some reflection going on in there -- seems likely. Is there any >> documentation / guidance about how to start the `ServerRuntime` without the >> DI mechanism? >> >> Caused by: org.apache.cayenne.di.DIRuntimeException: No applicable >> constructor is found for constructor injection in class >> 'org.apache.cayenne.log.Slf4jJdbcEventLogger' >> at >> org.apache.cayenne.di.spi.ConstructorInjectingProvider.initConstructor(ConstructorInjectingProvider.java:103) >> ~[na:na] >> at >> org.apache.cayenne.di.spi.ConstructorInjectingProvider.(ConstructorInjectingProvider.java:42) >> ~[na:na] >> at >> org.apache.cayenne.di.spi.DefaultBindingBuilder.to(DefaultBindingBuilder.java:44) >> ~[na:na] >> at >> org.apache.cayenne.configuration.server.ServerModule.configure(ServerModule.java:349) >> ~[na:na] >> at >> org.apache.cayenne.di.spi.DefaultInjector.(DefaultInjector.java:68) >> ~[na:na] >> at >> org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:38) >> ~[na:na] >> at >> org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:46) >> ~[na:na] >> at >> org.apache.cayenne.configuration.CayenneRuntime.(CayenneRuntime.java:79) >> ~[haikudepotserver-webapp:4.1.1] >> at >> org.apache.cayenne.configuration.server.ServerRuntime.(ServerRuntime.java:75) >> ~[haikudepotserver-webapp:4.1.1] >> at >> org.apache.cayenne.configuration.server.ServerRuntimeBuilder.build(ServerRuntimeBuilder.java:207) >> ~[na:na] >> >> Regards. >> >> -- >> Andrew Lindesay
Re: Graal (Native Image) with Cayenne
Yeah, would be great if you could share the JSON, but also outline the overall approach. And if this JOSN file is required for the process, we'd need a way to test and maintain it going forward. Andrus > On Apr 5, 2023, at 1:58 PM, Andrew Lindesay wrote: > > Hi Andrus; > > Thanks for coming back to me. It seems that for my situation, I need to let > the build tool know that each of the "injectable" classes should be allowed > to be scanned for constructors in the build product by supplying the Graal > build-tool with; > > ``` > -H:ReflectionConfigurationFiles=/...path.../reflection.json > ``` > > The snipped `reflection.json` file looks like; > > ``` > [ > { >"name": "org.apache.cayenne.access.DataDomain", >"queryAllDeclaredConstructors": true > }, > { >"name": > "org.apache.cayenne.access.dbsync.DefaultSchemaUpdateStrategyFactory", >"queryAllDeclaredConstructors": true > }, > ... continued > ] > ``` > > There are entries for 117 classes. It seems this file can be supplied with > the library jar in some way in order to instruct the Graal build tool. Maybe > once I have this fully working I can add a PR for it to cover the known > classes in the jar(s). > > Regards. > > -- > Andrew Lindesay > > On Wed, 5 Apr 2023, at 20:31, Andrus Adamchik wrote: >> Hi Andrew, >> >> I don't have first-hand experience, but Cayenne was reported to work >> with GraalVM. E.g.: >> https://lists.apache.org/list?user@cayenne.apache.org:2023-1:graalvm >> >> Andrus >> >> >>> On Apr 5, 2023, at 10:26 AM, Andrew Lindesay wrote: >>> >>> Hello; >>> >>> Has anybody here experimented with running an application using Cayenne >>> with the GraalVM "native image" compiler? The resultant executable seems >>> to be having a problem with the DI system at run time; probably because >>> there's some reflection going on in there -- seems likely. Is there any >>> documentation / guidance about how to start the `ServerRuntime` without the >>> DI mechanism? >>> >>> Caused by: org.apache.cayenne.di.DIRuntimeException: No applicable >>> constructor is found for constructor injection in class >>> 'org.apache.cayenne.log.Slf4jJdbcEventLogger' >>> at >>> org.apache.cayenne.di.spi.ConstructorInjectingProvider.initConstructor(ConstructorInjectingProvider.java:103) >>> ~[na:na] >>> at >>> org.apache.cayenne.di.spi.ConstructorInjectingProvider.(ConstructorInjectingProvider.java:42) >>> ~[na:na] >>> at >>> org.apache.cayenne.di.spi.DefaultBindingBuilder.to(DefaultBindingBuilder.java:44) >>> ~[na:na] >>> at >>> org.apache.cayenne.configuration.server.ServerModule.configure(ServerModule.java:349) >>> ~[na:na] >>> at >>> org.apache.cayenne.di.spi.DefaultInjector.(DefaultInjector.java:68) >>> ~[na:na] >>> at >>> org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:38) >>> ~[na:na] >>> at >>> org.apache.cayenne.di.DIBootstrap.createInjector(DIBootstrap.java:46) >>> ~[na:na] >>> at >>> org.apache.cayenne.configuration.CayenneRuntime.(CayenneRuntime.java:79) >>> ~[haikudepotserver-webapp:4.1.1] >>> at >>> org.apache.cayenne.configuration.server.ServerRuntime.(ServerRuntime.java:75) >>> ~[haikudepotserver-webapp:4.1.1] >>> at >>> org.apache.cayenne.configuration.server.ServerRuntimeBuilder.build(ServerRuntimeBuilder.java:207) >>> ~[na:na] >>> >>> Regards. >>> >>> -- >>> Andrew Lindesay
Re: Graal (Native Image) with Cayenne
Hello Andrus; The problem is that any class which is involved in the DI process where it might be the `implementation` in `ConstructorInjectingProvider` at... Constructor[] constructors = implementation.getDeclaredConstructors(); ...appears as if it is going to have to appear in the JSON list. This effectively means declaring the classes involved in the DI ahead of time. This is not really ideal. I guess those DI classes could be annotation-marked in the Cayenne project somehow and collected at build time and incorporated into the `.jar` build product for Graal to pickup? :-/ Regards. -- Andrew Lindesay On Thu, 6 Apr 2023, at 01:06, Andrus Adamchik wrote: > Yeah, would be great if you could share the JSON, but also outline the > overall approach. And if this JOSN file is required for the process, > we'd need a way to test and maintain it going forward.