Skip to content

Declare the dependency between shared session creator and entity instantiator. #2099

@steffen-harbich-cognitum

Description

I have a database migration script component as in the following code:

@Component
public class MigrationLogic {

    // + autowired repositories

    @PostConstruct
    @Transactional
    public void run() {
        // running migration logic, storing entities that rely on converter registered to ConversionService
    }
}

Produces the NullPointerException:

Caused by: java.lang.NullPointerException: null
at org.neo4j.ogm.typeconversion.ProxyAttributeConverter.toGraphProperty(ProxyAttributeConverter.java:56) ~[neo4j-ogm-core-3.2.18.jar:3.2.18]
at org.neo4j.ogm.metadata.FieldInfo.readProperty(FieldInfo.java:492) ~[neo4j-ogm-core-3.2.18.jar:3.2.18]

This is because Neo4jOgmEntityInstantiatorConfigurationBean has not been initialized at that point. I would expect it to be initialized once the repositories are available as spring bean. I need to run the migration script before tomcat embedded is opening REST API ports, so I cannot use an event like "context refreshed" to do the migration.

Workaround: Add

    @Autowired()
    @Qualifier("org.springframework.data.neo4j.repository.config.Neo4jOgmEntityInstantiatorConfigurationBean#0")
    private Object workaround;

which is of course an unwanted hack.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions