Skip to content

Errors when working with graalvm native compilation #2798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dimibe opened this issue Sep 21, 2023 · 6 comments
Closed

Errors when working with graalvm native compilation #2798

Dimibe opened this issue Sep 21, 2023 · 6 comments
Assignees
Labels
type: bug A general bug

Comments

@Dimibe
Copy link
Contributor

Dimibe commented Sep 21, 2023

Hello,

I have a Spring Boot Webflux application and want to create a native image. There I came across two different issues.

1. Saving nodes:
I'm getting an error when saving an node with a reactive repository. I was able to identify the problem. It seems that (at least) the runtime hint for the ReactiveBeforeBindCallback is missing. When adding the class to my projects runtime hints the saving of a node works as expected.
For the non-reactive class the hint is present (Neo4jRuntimeHints.java#L51) and saving works as expected.

2. Repository with abstract base class:

I have a class hierarchy setup where I have an abstract parent node class and several child classes (see below).
According to the section A note on class hierarchies this use case is supported.

@Node("ParentLabel")
abstract sealed class ParentNode permits ChildNodeA {
// constuctor and properties
}

@Node("ChildALabel")
final class ChildANode extends ParentNode {
 // constuctor and properties
}

@Repository
interface MyRepository extends ReactiveNeo4jRepository<ParentNode, String> {
    @Query("MATCH (t:ParentLabel {name: $name}) RETURN t")
    Mono<ParentNode> findByName(@Param("name") String name);
}

Saving a ChildNodeA works as expected resulting in a node with both labels ParentLabel and ChildALabel.
But when calling the findByName query an exception is thrown where it seems that it's tried to create an instance of ParentNode instead of ChildNodeA. Here I didn't found a solution myself.

This behavior is the same for both the reactive repository and the non-reactive repository. If not using graalvm the child class is correctly resolved and instanciated.

Below the exception from the reactive case:

 org.springframework.data.mapping.MappingException: Error mapping Record<{t: node<81>}>
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:123) ~[na:na]
        Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
        *__checkpoint ⇢ Handler com.example.graalvmtest.TestController#getTest2(String) [DispatcherHandler]
        *__checkpoint ⇢ HTTP GET "/test2/11" [ExceptionHandlingWebHandler]
Original Stack Trace:
                at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:123) ~[na:na]
                at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:71) ~[na:na]
                at org.springframework.data.neo4j.core.mapping.Schema.lambda$getRequiredMappingFunctionFor$0(Schema.java:96) ~[graalvm-test:7.2.0-M3]
                at org.springframework.data.neo4j.core.mapping.EntityInstanceWithSource.lambda$decorateMappingFunction$0(EntityInstanceWithSource.java:49) ~[graalvm-test:7.2.0-M3]
                at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:246) ~[na:na]
                at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:158) ~[na:na]
                at org.springframework.data.neo4j.core.DefaultReactiveNeo4jClient$DefaultRecordFetchSpec.lambda$executeWith$2(DefaultReactiveNeo4jClient.java:401) ~[na:na]
                at reactor.core.publisher.Flux.lambda$mapNotNull$24(Flux.java:6541) ~[graalvm-test:3.6.0-M3]
                at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:113) ~[na:na]
                at reactor.core.publisher.FluxCreate$IgnoreSink.next(FluxCreate.java:702) ~[na:na]
                at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:161) ~[graalvm-test:3.6.0-M3]
                at org.neo4j.driver.internal.reactivestreams.InternalReactiveResult.lambda$createRecordConsumer$3(InternalReactiveResult.java:91) ~[na:na]
                at org.neo4j.driver.internal.handlers.pulln.BasicPullResponseHandler.onRecord(BasicPullResponseHandler.java:162) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
                at org.neo4j.driver.internal.handlers.RoutingResponseHandler.onRecord(RoutingResponseHandler.java:66) ~[na:na]
                at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleRecordMessage(InboundMessageDispatcher.java:106) ~[na:na]
                at org.neo4j.driver.internal.messaging.common.CommonMessageReader.unpackRecordMessage(CommonMessageReader.java:73) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
                at org.neo4j.driver.internal.messaging.common.CommonMessageReader.read(CommonMessageReader.java:50) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
                at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:80) ~[na:na]
                at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:36) ~[na:na]
                at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[graalvm-test:4.1.97.Final]
                at org.neo4j.driver.internal.async.inbound.MessageDecoder.channelRead(MessageDecoder.java:42) ~[na:na]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1466) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1329) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1378) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
                at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[graalvm-test:4.1.97.Final]
                at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[na:na]
                at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[na:na]
                at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[na:na]
                at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[na:na]
                at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[na:na]
                at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[na:na]
                at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[na:na]
                at java.base@21/java.lang.Thread.runWith(Thread.java:1596) ~[graalvm-test:na]
                at java.base@21/java.lang.Thread.run(Thread.java:1583) ~[graalvm-test:na]
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833) ~[graalvm-test:na]
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211) ~[na:na]
Caused by: org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate com.example.graalvmtest.TestParent using constructor public com.example.graalvmtest.TestParent() with arguments 
        at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:97) ~[graalvm-test:3.2.0-M3]
        at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:98) ~[graalvm-test:3.2.0-M3]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.instantiate(DefaultNeo4jEntityConverter.java:491) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.lambda$map$2(DefaultNeo4jEntityConverter.java:324) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.map(DefaultNeo4jEntityConverter.java:343) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.map(DefaultNeo4jEntityConverter.java:301) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:121) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:71) ~[na:na]
        at org.springframework.data.neo4j.core.mapping.Schema.lambda$getRequiredMappingFunctionFor$0(Schema.java:96) ~[graalvm-test:7.2.0-M3]
        at org.springframework.data.neo4j.core.mapping.EntityInstanceWithSource.lambda$decorateMappingFunction$0(EntityInstanceWithSource.java:49) ~[graalvm-test:7.2.0-M3]
        at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:246) ~[na:na]
        at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:158) ~[na:na]
        at org.springframework.data.neo4j.core.DefaultReactiveNeo4jClient$DefaultRecordFetchSpec.lambda$executeWith$2(DefaultReactiveNeo4jClient.java:401) ~[na:na]
        at reactor.core.publisher.Flux.lambda$mapNotNull$24(Flux.java:6541) ~[graalvm-test:3.6.0-M3]
        at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:113) ~[na:na]
        at reactor.core.publisher.FluxCreate$IgnoreSink.next(FluxCreate.java:702) ~[na:na]
        at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:161) ~[graalvm-test:3.6.0-M3]
        at org.neo4j.driver.internal.reactivestreams.InternalReactiveResult.lambda$createRecordConsumer$3(InternalReactiveResult.java:91) ~[na:na]
        at org.neo4j.driver.internal.handlers.pulln.BasicPullResponseHandler.onRecord(BasicPullResponseHandler.java:162) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
        at org.neo4j.driver.internal.handlers.RoutingResponseHandler.onRecord(RoutingResponseHandler.java:66) ~[na:na]
        at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleRecordMessage(InboundMessageDispatcher.java:106) ~[na:na]
        at org.neo4j.driver.internal.messaging.common.CommonMessageReader.unpackRecordMessage(CommonMessageReader.java:73) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
        at org.neo4j.driver.internal.messaging.common.CommonMessageReader.read(CommonMessageReader.java:50) ~[graalvm-test:5.12.0-5bd7c0c762668653c02b042b55c6d983d5f245d9]
        at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:80) ~[na:na]
        at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:36) ~[na:na]
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[graalvm-test:4.1.97.Final]
        at org.neo4j.driver.internal.async.inbound.MessageDecoder.channelRead(MessageDecoder.java:42) ~[na:na]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1466) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1329) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1378) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[graalvm-test:4.1.97.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[na:na]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[na:na]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[na:na]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[na:na]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[na:na]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[na:na]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[na:na]
        at java.base@21/java.lang.Thread.runWith(Thread.java:1596) ~[graalvm-test:na]
        at java.base@21/java.lang.Thread.run(Thread.java:1583) ~[graalvm-test:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833) ~[graalvm-test:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211) ~[na:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.graalvmtest.TestParent]: Is it an abstract class?
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:213) ~[na:na]
        at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:95) ~[graalvm-test:3.2.0-M3]
        ... 70 common frames omitted
Caused by: java.lang.InstantiationException: Only non-abstract instance classes can be instantiated using reflection
        at java.base@21/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[graalvm-test:na]
        at java.base@21/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[graalvm-test:na]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:196) ~[na:na]
        ... 71 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 21, 2023
@michael-simons
Copy link
Collaborator

We are working on this, 1. will be addressed soon.

@michael-simons
Copy link
Collaborator

This is an oversight / bug in the Spring Boot autoconfiguration for SDN. I'll PR a fix with the team over there.
In the mean time, you can workaround this by adding some custom configuration like this:

import java.util.Set;

import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.aot.Neo4jManagedTypes;
import org.springframework.data.neo4j.core.convert.Neo4jConversions;
import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.RelationshipProperties;

@Configuration(proxyBeanMethods = false)
public class F {

	@Bean
	Neo4jManagedTypes neo4jManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
		Set<Class<?>> initialEntityClasses = new EntityScanner(applicationContext).scan(Node.class,
			RelationshipProperties.class);
		return Neo4jManagedTypes.fromIterable(initialEntityClasses);
	}

	@Bean
	public Neo4jMappingContext neo4jMappingContext(Neo4jManagedTypes managedTypes,
	                                               Neo4jConversions neo4jConversions) {

		Neo4jMappingContext context = new Neo4jMappingContext(neo4jConversions);
		context.setManagedTypes(managedTypes);
		return context;
	}
}

Please let me know if this works for you.

@Dimibe
Copy link
Contributor Author

Dimibe commented Sep 25, 2023

I have tested it in my project and it's working like a charm.

Thanks for the amazing support and the quick solution to the problem!

@michael-simons
Copy link
Collaborator

Thank you for using and reporting it :) The improvement on Spring Boot side of things is great.

@Dimibe
Copy link
Contributor Author

Dimibe commented Oct 20, 2023

Hi @michael-simons,
I just tested my code with spring-boot 3.1.5 and the workarounds are not needed anymore.
So I think this ticket is completed.

@michael-simons
Copy link
Collaborator

Oh excellent, thank you so much for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants