<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Cannot use BusinessDataRepository in JAX-RS resources</title><link>https://answers.axonivy.com/questions/3641/cannot-use-businessdatarepository-in-jax-rs-resources</link><description>&lt;p&gt;Hi Axon.ivy team,&lt;/p&gt;
&lt;p&gt;I know this questions had been asked long time ago at &lt;a href="https://answers.axonivy.com/questions/2777/can-not-use-ivy-repo-in-resfulapi."&gt;https://answers.axonivy.com/questions/2777/can-not-use-ivy-repo-in-resfulapi.&lt;/a&gt; But the question was for Axon.ivy 6.3.0 and there was never a resolution of the issue.&lt;/p&gt;
&lt;p&gt;I am using Axon.ivy 7.0.8 LTS and I still encountered the same issue.&lt;/p&gt;
&lt;p&gt;I introduce a JAX-RS resource:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package com.example.lab;

@PermitAll
@Path("awesome")
public class TheAwesomeApi {

    @POST
    @Consume("application/json")
    @Produces("text/plain")
    public String saveAwesomeMessage(AwesomeMessage message) {
        return Ivy.repo().save(message).getId();
    }

    public static class AwesomeMessage {
        private String content;
        // getter, setter
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I tried to call this API, the exception was returned.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;curl &lt;a href="http://localhost:8081/ivy/api/designer/awesome"&gt;http://localhost:8081/ivy/api/designer/awesome&lt;/a&gt; \
  -H 'Content-Type: application/json' \
  -d '{ "content" : "This is an awesome message" }'
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;full stacktrace can  be found here: &lt;a href="https://pastebin.com/hXcyQq6h"&gt;https://pastebin.com/hXcyQq6h&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Unable to provision, see the following errors:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1) Error in custom provider, java.lang.NullPointerException
  while locating ch.ivyteam.ivy.scripting.dataclass.internal.di.IvyCaseProjectClassLoaderProvider
  while locating java.lang.ClassLoader annotated with interface ch.ivyteam.ivy.scope.restricted.FromCaseScope
Caused by: java.lang.NullPointerException
    at ch.ivyteam.ivy.scripting.dataclass.internal.di.IvyCaseProjectClassLoaderProvider.get(IvyCaseProjectClassLoaderProvider.java:20)
    at ch.ivyteam.ivy.scripting.dataclass.internal.di.IvyCaseProjectClassLoaderProvider.get(IvyCaseProjectClassLoaderProvider.java:1)
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
    at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
    at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
    at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
    at ch.ivyteam.ivy.business.data.store.restricted.BusinessDataTypeLoader.getContextClassLoader(BusinessDataTypeLoader.java:60)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.serialize(BusinessDataRepositoryImpl.java:369)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.lambda$0(BusinessDataRepositoryImpl.java:196)
    at ch.ivyteam.ivy.business.data.store.internal.ElasticSystemDbPersistence.lambda$14(ElasticSystemDbPersistence.java:439)
    at ch.ivyteam.ivy.persistence.base.AbstractPersistencyService.execute(AbstractPersistencyService.java:177)
    at ch.ivyteam.ivy.persistence.base.ClassPersistencyService.execute(ClassPersistencyService.java:673)
    at ch.ivyteam.ivy.business.data.store.internal.ElasticSystemDbPersistence.executeInTransaction(ElasticSystemDbPersistence.java:435)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.create(BusinessDataRepositoryImpl.java:194)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.save(BusinessDataRepositoryImpl.java:177)
    at com.example.lab.axonivy.api.TheAwesomeApi.saveAwesomeMessage(TheAwesomeApi.java:35)
    ....
    at java.lang.Thread.run(Thread.java:748)

2) Error in custom provider, com.google.inject.OutOfScopeException: No case available in the current scope/context
  while locating ch.ivyteam.ivy.workflow.internal.di.CaseProvider
  while locating ch.ivyteam.ivy.workflow.ICase
    for field at ch.ivyteam.ivy.scripting.dataclass.internal.di.IvyCaseProjectClassLoaderProvider.caze(IvyCaseProjectClassLoaderProvider.java:1)
  while locating ch.ivyteam.ivy.scripting.dataclass.internal.di.IvyCaseProjectClassLoaderProvider
  while locating java.lang.ClassLoader annotated with interface ch.ivyteam.ivy.scope.restricted.FromCaseScope
Caused by: com.google.inject.OutOfScopeException: No case available in the current scope/context
    at ch.ivyteam.ivy.workflow.internal.di.CaseProvider.get(CaseProvider.java:24)
    at ch.ivyteam.ivy.workflow.internal.di.CaseProvider.get(CaseProvider.java:1)
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
    at com.google.inject.internal.ProvidedByInternalFactory.provision(ProvidedByInternalFactory.java:82)
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
    at com.google.inject.internal.ProvidedByInternalFactory.get(ProvidedByInternalFactory.java:71)
    at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54)
    at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
    at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:120)
    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
    at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
    at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
    at ch.ivyteam.ivy.business.data.store.restricted.BusinessDataTypeLoader.getContextClassLoader(BusinessDataTypeLoader.java:60)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.serialize(BusinessDataRepositoryImpl.java:369)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.lambda$0(BusinessDataRepositoryImpl.java:196)
    at ch.ivyteam.ivy.business.data.store.internal.ElasticSystemDbPersistence.lambda$14(ElasticSystemDbPersistence.java:439)
    at ch.ivyteam.ivy.persistence.base.AbstractPersistencyService.execute(AbstractPersistencyService.java:177)
    at ch.ivyteam.ivy.persistence.base.ClassPersistencyService.execute(ClassPersistencyService.java:673)
    at ch.ivyteam.ivy.business.data.store.internal.ElasticSystemDbPersistence.executeInTransaction(ElasticSystemDbPersistence.java:435)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.create(BusinessDataRepositoryImpl.java:194)
    at ch.ivyteam.ivy.business.data.store.internal.BusinessDataRepositoryImpl.save(BusinessDataRepositoryImpl.java:177)
    at com.example.lab.axonivy.api.TheAwesomeApi.saveAwesomeMessage(TheAwesomeApi.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at ch.ivyteam.ivy.webserver.internal.rest.resource.project.RestPmvInvocationHandler$PmvAwareInvocator.lambda$0(RestPmvInvocationHandler.java:38)
    at ch.ivyteam.ivy.webserver.internal.rest.resource.project.RestPmvInvocationHandler.executeWithIvyContext(RestPmvInvocationHandler.java:70)
    at ch.ivyteam.ivy.webserver.internal.rest.resource.project.RestPmvInvocationHandler.access$1(RestPmvInvocationHandler.java:65)
    at ch.ivyteam.ivy.webserver.internal.rest.resource.project.RestPmvInvocationHandler$PmvAwareInvocator.invoke(RestPmvInvocationHandler.java:50)
    ...
    at java.lang.Thread.run(Thread.java:748)

2 errors"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is this issue still a known limitation even with the 7.0 LTS?&lt;/p&gt;
&lt;p&gt;Thanks for your support!&lt;/p&gt;
&lt;p&gt;Jack&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3641/cannot-use-businessdatarepository-in-jax-rs-resources" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 29 Jan 2019 03:39:23 -0500</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/3641/cannot-use-businessdatarepository-in-jax-rs-resources/3643</link><description>&lt;p&gt;The &lt;a href="https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/ivy/business/data/store/BusinessDataRepository.html"&gt;BusinessDataRepository&lt;/a&gt; is designed and powerful because the data in it is usually attached to a &lt;a href="https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/ivy/workflow/businesscase/IBusinessCase.html"&gt;IBusinessCase&lt;/a&gt;. So it makes sort of sense to me that the example here does not work with the ivy.repo() API as there is no Task or Case set up when a client uses the REST api.&lt;/p&gt;
&lt;p&gt;But the relation (between repo &amp;amp; BusinessData) is not strictly enforced and lives in a separate db table. 
So it looks like a minor bug to me. I opened an issue for it: &lt;a href="https://jira.axonivy.com/jira/browse/XIVY-3074"&gt;https://jira.axonivy.com/jira/browse/XIVY-3074&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Workaround up till then: store data that is associated with a &lt;a href="https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/ivy/workflow/businesscase/IBusinessCase.html"&gt;IBusinessCase&lt;/a&gt; in a process. Within it you have a Task/Case.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 29 Jan 2019 03:39:23 -0500</pubDate><guid>https://answers.axonivy.com/questions/3641/cannot-use-businessdatarepository-in-jax-rs-resources/3643</guid></item></channel></rss>