eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
231 stars 72 forks source link

[BUG] DocumentTemplate results in Exception running jnosql in Tomee 9.1.0 #400

Closed tlappe closed 1 year ago

tlappe commented 1 year ago

Which JNoSQL project the issue refers to?

JNoSQL (Core)

Bug description

I'm trying to upgrade my application from 0.0.6 to 1.0.0 and to use @Inject to get a DocumentTemplate instead of using a Repository. I don't know if I'm doing something wrong or there is a problem in jnosql's code. It always ends in an exception starting my app in tomee 9.1.0. So I create a clean new project in Eclipse to understand what's going on.

Deploying the app to Tomee 9.1.0 results in:

Juli 03, 2023 12:54:36 PM org.apache.openejb.assembler.classic.Assembler createApplication
INFORMATION: Assembling app: /home/tim/Development/workspaces/channels/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jnosql-test
Juli 03, 2023 12:54:36 PM org.apache.openejb.cdi.CdiBuilder initSingleton
INFORMATION: Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@3300f4fd
Juli 03, 2023 12:54:37 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
INFORMATION: OpenWebBeans Container is starting...
Juli 03, 2023 12:54:37 PM org.apache.webbeans.plugins.PluginLoader startUp
INFORMATION: Adding OpenWebBeansPlugin : [CdiPlugin]
Juli 03, 2023 12:54:37 PM org.apache.openejb.cdi.CdiScanner handleBda
INFORMATION: Using annotated mode for jar:file:/home/tim/Development/workspaces/channels/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jnosql-test/WEB-INF/lib/jnosql-mapping-core-1.0.0.jar!/META-INF/beans.xml looking all classes to find CDI beans, maybe think to add a beans.xml if not there or add the jar to exclusions.list
Juli 03, 2023 12:54:37 PM org.apache.openejb.cdi.CdiScanner handleBda
INFORMATION: Using annotated mode for jar:file:/home/tim/Development/workspaces/channels/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jnosql-test/WEB-INF/lib/jnosql-mapping-document-1.0.0.jar!/META-INF/beans.xml looking all classes to find CDI beans, maybe think to add a beans.xml if not there or add the jar to exclusions.list
Juli 03, 2023 12:54:37 PM org.eclipse.jnosql.mapping.reflection.ClassOperationFactory get
INFORMATION: Logging the operation factory
Juli 03, 2023 12:54:37 PM org.eclipse.jnosql.mapping.reflection.ClassOperationFactory get
INFORMATION: ClassOperation does not found, using the default implementation
Juli 03, 2023 12:54:41 PM org.eclipse.jnosql.mapping.document.spi.DocumentExtension onAfterBeanDiscovery
INFORMATION: Processing Document extension: 0 databases crud 0 found
Juli 03, 2023 12:54:41 PM org.eclipse.jnosql.mapping.document.spi.DocumentExtension onAfterBeanDiscovery
INFORMATION: Processing repositories as a Document implementation: []
Juli 03, 2023 12:54:41 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
SCHWERWIEGEND: CDI Beans module deployment failed
org.apache.webbeans.exception.WebBeansDeploymentException: jakarta.enterprise.inject.UnproxyableResolutionException: WebBeans with api type with normal scope must be proxyable.
org.eclipse.jnosql.mapping.document.DefaultDocumentTemplate has no explicit no-arg constructor!A public or protected constructor without args is required!
    at org.apache.webbeans.container.InjectionResolver.checkInjectionPointType(InjectionResolver.java:188)
    at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1214)
    at org.apache.webbeans.util.WebBeansUtil.validate(WebBeansUtil.java:1521)
    at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:1220)
    at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:1131)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:323)
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:196)
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:268)
    at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:43)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:974)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:762)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1340)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1162)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:134)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5085)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:886)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:795)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Caused by: jakarta.enterprise.inject.UnproxyableResolutionException: WebBeans with api type with normal scope must be proxyable.
org.eclipse.jnosql.mapping.document.DefaultDocumentTemplate has no explicit no-arg constructor!A public or protected constructor without args is required!
    at org.apache.webbeans.util.InjectionExceptionUtil.createUnproxyableResolutionException(InjectionExceptionUtil.java:44)
    at org.apache.webbeans.config.DeploymentValidationService.validateProxyable(DeploymentValidationService.java:142)
    at org.apache.webbeans.component.creation.ManagedBeanBuilder.getBean(ManagedBeanBuilder.java:71)
    at org.apache.webbeans.config.BeansDeployer.defineManagedBean(BeansDeployer.java:2045)
    at org.apache.webbeans.config.BeansDeployer.deploySingleAnnotatedType(BeansDeployer.java:1634)
    at org.apache.webbeans.config.BeansDeployer.deployFromBeanAttributes(BeansDeployer.java:1586)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:306)
    ... 38 more

JNoSQL Version

1.0.0

Steps To Reproduce

  1. Create new project in IDE (I'm using Eclipse)
  2. Add the dependencies
  3. Add the class TestCar
  4. Add the microprofile-config.properties
  5. Deploy to Tomee 9.1.0.

Expected Results

No exception and DocumentTemplate injected.

Code example, screenshot, or link to a repository

Starting a new project with

dependencies {
    compileOnly 'jakarta.platform:jakarta.jakartaee-web-api:9.1.0'

    implementation 'org.eclipse.jnosql.databases:jnosql-couchdb:1.0.0'
    implementation 'org.eclipse.jnosql.mapping:jnosql-mapping-document:1.0.0'
    implementation 'org.eclipse.microprofile.config:microprofile-config-api:1.3'
}
package de.timlappe.jnosqltest;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.nosql.document.DocumentTemplate;

@ApplicationScoped
public class CarApp {
    @Inject
    DocumentTemplate template;

    public CarApp() {
    }
}

src/main/webapp/META-INF/microprofile-config.properties

jnosql.document.provider=org.eclipse.jnosql.databases.couchdb.communication.CouchDBDocumentConfiguration
jnosql.document.database=database
jnosql.couchdb.host=localhost
jnosql.couchdb.username=user
jnosql.couchdb.password=password
otaviojava commented 1 year ago

@tlappe did you try adding the "openejb.additional.include"

https://github.com/otaviojava/tomee-jnosql-sample/blob/main/pom.xml#L44L46

otaviojava commented 1 year ago

I've updated this repository, and I got this exception:

org.eclipse.jnosql.mapping.document.DefaultDocumentTemplate has no explicit no-arg constructor! A public or protected constructor without args is required!

So, we need to return all beans to have a no-arg constructor.

dearrudam commented 1 year ago

@otaviojava, I'm just curious... is this requirement a default one of the CDI? I'm asking about it because we didn't face this problem when we worked on the sample codes https://github.com/JNOSQL/demos-se/tree/main/mongodb and https://github.com/JNOSQL/demo-ee/tree/main/liberty-mongodb...

I've just figured out that another DocumentTemplate implementation (e.g: https://github.com/eclipse/jnosql-databases/blob/42881b7d97b6e3be73c4d53ebf788af102c259e2/jnosql-couchbase/src/main/java/org/eclipse/jnosql/databases/couchbase/mapping/DefaultCouchbaseTemplate.java#L70C1-L71C6) has a no-arg constructor... then we should add to all CDI beans a no-arg constructor in order to avoid this issue...

dearrudam commented 1 year ago

@otaviojava, I'm gonna work on it!

otaviojava commented 1 year ago

@dearrudam, it works on CDI Weld by Red Hat.

otaviojava commented 1 year ago

@dearrudam, we need to check any inject bean that does not provide a no-arg constructor and return it to the original.

otaviojava commented 1 year ago

@dearrudam I took this one here: https://github.com/eclipse/jnosql-databases/pull/231

otaviojava commented 1 year ago

@dearrudam @tlappe I've updated the sample project with the newest version of both TomEE and Eclipsel JNoSQL:

https://github.com/otaviojava/tomee-jnosql-sample/

Please, let me know what you think.

Ps:: Max, what do you think about moving this sample to the demo-ee one?

dearrudam commented 1 year ago

@otaviojava I liked this idea! I've used this project to test locally the changes of the PR https://github.com/eclipse/jnosql/pull/402... I'll move it to there at demo-ee samples!!

otaviojava commented 1 year ago

@tlappe, thank you, it is fixed, and we will release version 1.0.1 ASAP. It will probably be at the end of the month.

dearrudam commented 1 year ago

@otaviojava will you release a SNAPSHOT version?

otaviojava commented 1 year ago

@dearrudam it is already as 1.0.1-SNAPSHOT!