eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to Read HashMap<String, Object> from CouchDB with Artemis

sebastian-x86 opened this issue · comments

Hi,

I currently have an issue with mapping a HashMap<String, Object> in Columns. It is possible to write the map into my couchdb database but I receive an error when reading it.

Java Version: 11.0.5
Applicationserver Version (OpenLiberty): 20.0.0.2

JNOSQL Version:

org.eclipse.jnosql.artemis
artemis-document
1.0.0-b2

org.eclipse.jnosql.artemis artemis-core 1.0.0-b2 org.eclipse.jnosql.diana couchdb-driver compile 1.0.0-b2

Entity:

import jakarta.nosql.mapping.Column;
import jakarta.nosql.mapping.Entity;
import jakarta.nosql.mapping.Id;
import lombok.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Entity("user_scope_properties_broken")
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class UserScopePropertiesBroken implements Serializable {

    @Id
    @NonNull
    private String userName;

    @Column("scope")
    @NonNull
    private String scope;

    @Column("properties")
    private Map<String, Object> properties = new HashMap<>();

}

Write and read entity:

@RequestScoped
public class UserService {

    @Inject
    @ConfigProperty(name = "document")
    private DocumentTemplate template;


	public void doDbStuff(String userName, String scope) {
		
		// WRITE
		final String randomUserName1 = userName + RandomGenerator.getRandomNumber(1,1000);
        UserScopePropertiesBroken entity1 = new UserScopePropertiesBroken();
        entity1.setUserName(randomUserName1);
        entity1.setScope(scope);
        entity1.getProperties().put("hallo", "Welt");
        template.insert(entity1);
		
		// READ (fails!)
		final DocumentQuery query1 = select().from("user_scope_properties_broken").where("_id").eq(randomUserName1).and("scope").eq(scope).build();
        final Optional<Object> first1 = template.select(query1).findFirst();
	}

Document in Database

{
  "_id": "joe984",
  "_rev": "1-e416f1d1977f12716c5134b24dacd1d4",
  "properties": {
    "hallo": "Welt"
  },
  "scope": "xxxx",
  "@entity": "user_scope_properties_broken"
}

Error messages:
There is not supported convertDocument{name='hallo', value=DefaultValue{value=Welt}} a not Map type.

java.lang.UnsupportedOperationException: There is not supported convertDocument{name='hallo', value=DefaultValue{value=Welt}} a not Map type.
        at org.eclipse.jnosql.diana.reader.MapTypeReferenceReader.getMap(MapTypeReferenceReader.java:94)
        at org.eclipse.jnosql.diana.reader.MapTypeReferenceReader.convert(MapTypeReferenceReader.java:67)
        at jakarta.nosql.TypeReferenceReaderDecorator.convert(TypeReferenceReaderDecorator.java:53)
        at org.eclipse.jnosql.diana.DefaultValue.get(DefaultValue.java:57)
        at org.eclipse.jnosql.artemis.reflection.GenericFieldMapping.getValue(GenericFieldMapping.java:54)
        at org.eclipse.jnosql.artemis.document.DocumentFieldConverters$DefaultConverter.convert(DocumentFieldConverters.java:120)
        at org.eclipse.jnosql.artemis.document.AbstractDocumentEntityConverter.lambda$feedObject$5(AbstractDocumentEntityConverter.java:120)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1603)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at org.eclipse.jnosql.artemis.document.AbstractDocumentEntityConverter.convertEntity(AbstractDocumentEntityConverter.java:109)
        at org.eclipse.jnosql.artemis.document.AbstractDocumentEntityConverter.toEntity(AbstractDocumentEntityConverter.java:95)
        at org.eclipse.jnosql.artemis.document.DefaultDocumentEntityConverter$Proxy$_$$_WeldClientProxy.toEntity(Unknown Source)
        at org.eclipse.jnosql.artemis.document.AbstractDocumentTemplate.lambda$executeQuery$7(AbstractDocumentTemplate.java:239)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1632)
        at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
        at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
        at cs.argos.kvs.service.UserService.getUserProperties(UserService.java:72)
        at cs.argos.kvs.service.UserService$Proxy$_$$_WeldSubclass.getUserProperties$$super(Unknown Source)
        at jdk.internal.reflect.GeneratedMethodAccessor849.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)
        at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
        at com.ibm.ws.microprofile.metrics.cdi23.interceptors.CountedInterceptor.countedCallable(CountedInterceptor.java:89)
        at com.ibm.ws.microprofile.metrics.cdi23.interceptors.CountedInterceptor.countedMethod(CountedInterceptor.java:73)
        at jdk.internal.reflect.GeneratedMethodAccessor848.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
        at cs.argos.kvs.service.UserService$Proxy$_$$_WeldSubclass.getUserProperties(Unknown Source)
        at cs.argos.kvs.service.UserService$Proxy$_$$_WeldClientProxy.getUserProperties(Unknown Source)
        at cs.argos.kvs.resources.UserResource.getScopedUserProperties(UserResource.java:24)
        at jdk.internal.reflect.GeneratedMethodAccessor836.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.ibm.ws.jaxrs20.cdi.component.JaxRsFactoryImplicitBeanCDICustomizer.serviceInvoke(JaxRsFactoryImplicitBeanCDICustomizer.java:342)
        at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:641)
        at com.ibm.ws.jaxrs20.server.LibertyJaxRsInvoker.performInvocation(LibertyJaxRsInvoker.java:160)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:101)
        at com.ibm.ws.jaxrs20.server.LibertyJaxRsInvoker.invoke(LibertyJaxRsInvoker.java:273)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:205)
        at com.ibm.ws.jaxrs20.server.LibertyJaxRsInvoker.invoke(LibertyJaxRsInvoker.java:444)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:111)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:275)
        at com.ibm.ws.jaxrs20.endpoint.AbstractJaxRsWebEndpoint.invoke(AbstractJaxRsWebEndpoint.java:137)
        at com.ibm.websphere.jaxrs.server.IBMRestServlet.handleRequest(IBMRestServlet.java:146)
        at com.ibm.websphere.jaxrs.server.IBMRestServlet.doGet(IBMRestServlet.java:112)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
        at com.ibm.websphere.jaxrs.server.IBMRestServlet.service(IBMRestServlet.java:96)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1257)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:745)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:442)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:182)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:93)
        at org.keycloak.adapters.servlet.KeycloakOIDCFilter.doFilter(KeycloakOIDCFilter.java:206)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:201)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:90)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:1001)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1139)
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5057)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.handleRequest(DynamicVirtualHost.java:314)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1005)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:279)
        at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1146)
        at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:427)
        at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:386)
        at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:565)
        at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:499)
        at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:359)
        at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:326)
        at com.ibm.ws.channel.ssl.internal.SSLConnectionLink.determineNextChannel(SSLConnectionLink.java:1100)
        at com.ibm.ws.channel.ssl.internal.SSLConnectionLink.readyInboundPostHandshake(SSLConnectionLink.java:757)
        at com.ibm.ws.channel.ssl.internal.SSLConnectionLink$MyHandshakeCompletedCallback.complete(SSLConnectionLink.java:427)
        at com.ibm.ws.channel.ssl.internal.SSLUtils.handleHandshake(SSLUtils.java:954)
        at com.ibm.ws.channel.ssl.internal.SSLHandshakeIOCallback.complete(SSLHandshakeIOCallback.java:85)
        at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504)
        at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574)
        at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:958)
        at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1047)
        at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:239)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

Is this the correct way to handle HashMaps?

Best Regards
Sebastian

Hey @Linuem thank you for the issue report, I'll take a lot and then return later today.

Hey @libingw I found the issue:

Hope, we'll release a new version with these fixes next month.

@otaviojava What about the MicroProfile issue, do you expect that to be resolved next month?

Good Morning @otaviojava, this sounds pretty great!

Would be great to see a release next month. I think jnosql brings great value for nosql databases.

Currently I am using an ugly workaround with a custom converter:

public class MapConverter implements AttributeConverter<Map<String, Object>, String> {

        @Override
        public String convertToDatabaseColumn(Map<String, Object> stringObjectMap) {
             // TODO error handling (-:
             return new ObjectMapper().writeValueAsString(stringObjectMap);
        }

        @Override
        public Map<String, Object> convertToEntityAttribute(String dbValue) {
            // TODO error handling (-:
            return new ObjectMapper().readValue(jsonString, new TypeReference<Map<String, Object>>() {});
        }
    }

But this is of course not the best solution as I have not all CouchDb features when using serialized json.

Hey @Linuem , it is available as 1.0.0-SNAPSHOT.
Could you try with this version just to check if we fix the bug properly?

https://ci.eclipse.org/jnosql/view/Deploy/

Hi @otaviojava,

Yes, I would like to test it! From which maven repository is this available?

My maven resolves it to oss.sonatype.org but when I look at the pom it tells me that its date is not of today.

https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/jnosql/diana/couchdb-driver/1.0.0-SNAPSHOT/maven-metadata.xml

<metadata modelVersion="1.1.0">
<groupId>org.eclipse.jnosql.diana</groupId>
<artifactId>couchdb-driver</artifactId>
<version>1.0.0-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20201011.150225</timestamp>
<buildNumber>13</buildNumber>
</snapshot>
<lastUpdated>20201018132605</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<classifier>javadoc</classifier>
<extension>jar</extension>
<value>1.0.0-20201011.150225-13</value>
<updated>20201011150225</updated>
</snapshotVersion>
<snapshotVersion>
<classifier>sources</classifier>
<extension>jar</extension>
<value>1.0.0-20201011.150225-13</value>
<updated>20201011150225</updated>
</snapshotVersion>
<snapshotVersion>
<extension>jar</extension>
<value>1.0.0-20201011.150225-13</value>
<updated>20201011150225</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>1.0.0-20201011.150225-13</value>
<updated>20201011150225</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>

Best Regards,
Sebastian

@Linuem

We had an issue with the name, but briefly, we're not enabled to use "Artemis" and "Diana" anymore.
Instead of that, we replaced "communication" and "mapping" in the respective order.

https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/jnosql/communication/couchdb-driver/1.0.0-SNAPSHOT/maven-metadata.xml

Hi @otaviojava,

I just had the chance to test the snapshot version and it works great!

I had some serious issues with my applicationserver (openliberty) because it was complaining that all jakarta.nosql.* classes could not be found. I had to add them separately in my server.xml with:

...
<webApplication location="app.war" contextRoot="/">
        <classloader apiTypeVisibility="spec, ibm-api, api, stable, third-party" commonLibraryRef="Lib"/>
    </webApplication>

    <!-- WORKAROUND because openliberty will throw classnotfound exceptions for all jakarta.nosql.* classes -->
    <library id="Lib" apiTypeVisibility="spec, ibm-api, api, stable, third-party">
        <fileset dir="/home/xxx/Desktop/temp" includes="*.jar" scanInterval="5s" /> <!-- directory includes all jakarta deps -->
    </library>
...

I think this is related to openliberty but I am not that deep into openliberty. They are packaged in my war file but not found.

A further minor suggestion would be to add a bom :-)

From my point of view the main issue with HashMap is fixed.

Hey @Linuem we've released the sp3 version.
I'll close this issue, please, let me know if the issue persist.