Componentmanager and/or querymanager is null

Hello Everyone,
i am new member and im working on a project that is a java ee Rest Api inside the Xwiki.
until now i could read from xwiki database and send some information from gui to my rest Api and save it into database with Entitymanager persist. until now everything was ok.
now im trying to become XwikiDocument from database and delete them with all the objects and everything that belong to this Document.
As a solution i thought it is bette to use xwiki querymanager to get a XwikiDocument from database and call the Document.delete() functon, that deletes the documents and all the other things that belongs to it.
i tryed to @Inject querymanager or @Inject componentmanager but both were null.
i tryed it too :
EmbeddableComponentManager componentManager = new EmbeddableComponentManager();
componentManager.initialize(this.getClass().getClassLoader());
QueryManager queryManager = (QueryManager)componentManager.getInstance(QueryManager.class);

but the errors are like this:

2022-10-12 00:14:00,184 [DefaultQuartzScheduler_Worker-1] ERROR c.a.i.KsuService - error of querymanager
org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.query.internal.DefaultQueryManager] identified by type [interface org.xwiki.query.QueryManager] and hint [null]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:189)
at com.acme.internal.KsuService.get(KsuService.java:215)
at com.acme.internal.job.SchdeularKsuCheckJob.executeJob(SchdeularKsuCheckJob.java:88)
at com.xpn.xwiki.plugin.scheduler.AbstractJob.execute(AbstractJob.java:76)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.query.internal.DefaultQueryExecutorManager] identified by type [interface org.xwiki.query.QueryExecutorManager] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 6 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [com.xpn.xwiki.internal.query.ConfiguredQueryExecutorProvider] identified by type [javax.inject.Provider<org.xwiki.query.QueryExecutor>] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:399)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 10 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [com.xpn.xwiki.store.hibernate.query.DefaultQueryExecutor] identified by type [interface org.xwiki.query.QueryExecutor] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 14 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor] identified by type [interface org.xwiki.query.QueryExecutor] and hint [hql]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 18 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [com.xpn.xwiki.internal.store.hibernate.HibernateStore] identified by type [class com.xpn.xwiki.internal.store.hibernate.HibernateStore] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 22 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptorManager] identified by type [interface org.xwiki.wiki.descriptor.WikiDescriptorManager] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 26 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.wiki.internal.manager.WikiDescriptorCache] identified by type [class org.xwiki.wiki.internal.manager.WikiDescriptorCache] and hint [default]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:406)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:355)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 30 common frames omitted
Caused by: org.xwiki.component.phase.InitializationException: Failed to initialize wiki descriptor caches [wiki.descriptor.cache.wikiAlias]
at org.xwiki.wiki.internal.manager.WikiDescriptorCache.createCache(WikiDescriptorCache.java:71)
at org.xwiki.wiki.internal.manager.WikiDescriptorCache.initialize(WikiDescriptorCache.java:59)
at org.xwiki.component.embed.InitializableLifecycleHandler.handle(InitializableLifecycleHandler.java:39)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:365)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 34 common frames omitted
Caused by: org.xwiki.cache.CacheException: Failed to get cache factory for role hint [infinispan]
at org.xwiki.cache.internal.DefaultCacheManager.createNewCache(DefaultCacheManager.java:109)
at org.xwiki.cache.internal.DefaultCacheManager.createNewCache(DefaultCacheManager.java:85)
at org.xwiki.wiki.internal.manager.WikiDescriptorCache.createCache(WikiDescriptorCache.java:68)
… 39 common frames omitted
Caused by: org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.cache.infinispan.internal.InfinispanCacheFactory] identified by type [interface org.xwiki.cache.CacheFactory] and hint [infinispan]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:204)
at org.xwiki.cache.internal.DefaultCacheManager.createNewCache(DefaultCacheManager.java:107)
… 41 common frames omitted
Caused by: java.lang.RuntimeException: The Servlet Environment has not been properly initialized (The Servlet Context is not set)
at org.xwiki.environment.internal.ServletEnvironment.getServletContext(ServletEnvironment.java:63)
at org.xwiki.environment.internal.ServletEnvironment.getResourceAsStream(ServletEnvironment.java:72)
at org.xwiki.cache.infinispan.internal.InfinispanCacheFactory.getConfigurationFileAsStream(InfinispanCacheFactory.java:139)
at org.xwiki.cache.infinispan.internal.InfinispanCacheFactory.initialize(InfinispanCacheFactory.java:101)
at org.xwiki.component.embed.InitializableLifecycleHandler.handle(InitializableLifecycleHandler.java:39)
at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:365)
at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:451)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:201)
… 42 common frames omitted

please help me. i dont have much time :frowning: when i just can have a document instance from database and delete it, thats it. how should i do it?

This is really not what you should do when you are in an XWiki environment where the component manager(s) are already initialized.

See https://extensions.xwiki.org/xwiki/bin/view/Extension/Component%20Module#HAccessingcomponentsinlegacycode for more details on how to access components in non components.

1 Like

thank you very much i could finally use query manager.

I wanted to have a Document but ive got XwikiDocument.
i made an emty XwikiContext and made with the costructor Document( XwikiDocument , XwikiContext)
and called the delete function.
but i have this error:

Caused by: com.xpn.xwiki.XWikiException: Error number 3204 in 3: Impossible to delete document xwiki:parent.WebHome if it is not loaded
at com.xpn.xwiki.store.XWikiHibernateStore.deleteXWikiDoc(XWikiHibernateStore.java:1208)

i think it is because of empty XwikiContext. i dont know how to have the XwikiContext in my java class.

i just want to delete a document. is that possible?