cancel
Showing results for 
Search instead for 
Did you mean: 

User defined function database not starting

genealogy
Graph Buddy

I'm writing a user defined function querying the Neo4j 4.3.2 Enterprise database using Maven. I'm also have in the plugin folder apoc with the same driver version and gds. The error involves not routing properly, but the fixes found in my searching did not resolve the problem. What should I try?

The function:

package gen;
    import org.neo4j.driver.AuthTokens;
    import org.neo4j.driver.Driver;
    import org.neo4j.driver.GraphDatabase;
    import org.neo4j.driver.Result;
    import org.neo4j.driver.Session;    
    import org.neo4j.driver.SessionConfig;
    import org.neo4j.driver.Transaction;
    import org.neo4j.driver.TransactionWork;
    import org.neo4j.procedure.Name;
    import org.neo4j.procedure.UserFunction;
    import org.neo4j.procedure.Description;

    import static org.neo4j.driver.Values.parameters;
  
    
    public class mrca {          
                       

    public String mrca(
        @Name("db") 
            String db,
        @Name("rn1") 
            Long rn1,
        @Name("rn2") 
            Long rn2
      
)
    {
        
        { 
        String r =JavaQuery("stumpf");
       return r;
            }
     }
   
    public String JavaQuery(String db){
    
    String qrystr = "match (p1:Person{RN:1})-[r1:father|mother*0..15]->(mrca:Person)<-[r2:father|mother*0..15]-(p2:Person{RN:238}) return mrca.fullname + ' [' + mrca.RN + '] (' + left(mrca.BD,4) +'-' + left(mrca.DD,4) +')'" ;
      Driver driver;
        driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "cns105" ) );
        Session session = driver.session() ;
        try ( Session java_session = driver.session(SessionConfig.forDatabase(db)) )
        {
            String javasession = java_session.writeTransaction(new TransactionWork<String>()
            {
                @Override
                public String execute( Transaction tx )
                {
                    Result result = tx.run( qrystr,
                            parameters( "message", qrystr ) );

                    String output = "";
                        while (result.hasNext())
                        { output = output + result.next().values() + "\n";
                        
                        }
	                return output;
                            
                    
                }
            } );
           
            return javasession ;
        }
    }


}

The pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--https://github.com/neo4j-examples/neo4j-procedure-template/blob/4.2/pom.xml#L24-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>wai.neo4j.gen</groupId>
    <artifactId>wai.neo4j.gen</artifactId>
    <version>1.2</version>
    <packaging>jar</packaging>
    <name>gen</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <neo4j.version>4.2.6</neo4j.version>
        <junit-jupiter.version>5.7.0</junit-jupiter.version>
        <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <assertj.version>3.18.1</assertj.version>
   </properties>

    <dependencies>
<!--necessary to start neo4j-->
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <!--<version>4.2.7</version>-->
            <version>4.3.0</version>
            <scope>provided</scope> 
        </dependency>
        <!--drivers in plugins must be the same-->
         <dependency>
            <groupId>org.neo4j.driver</groupId>
            <artifactId>neo4j-java-driver</artifactId>
            <version>4.3.0</version>
         </dependency>
        <dependency>
            <groupId>org.neo4j.test</groupId>
            <artifactId>neo4j-harness</artifactId>
            <version>${neo4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--<dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>procedure-compiler</artifactId>
            <version>4.3.3</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>-->
    </dependencies>
    
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
      </plugin>
  
      <plugin>
        <!-- This generates a jar-file with our procedure code,
             plus any dependencies marked as `compile` scope.
             This should then be deployed in the `plugins` directory
             of each Neo4j instance in your deployment.
             After a restart, the procedure is available for calling. -->
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.7.1</version>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <!--https://stackoverflow.com/questions/25842559/valid-jar-signature-for-javafx-projects-->
          <excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The error when restarting the database:

2021-08-25 16:27:30.460+0000 ERROR [o.n.g.f.DatabaseManagementServiceFactory] Error starting Neo4j database server at C:\Users\david\AppData\Local\Neo4j\Relate\Data\dbmss\dbms-02d28c77-eb91-45e9-ba16-b3d70dff733e\data\databases
org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.procedure.impl.GlobalProceduresRegistry@1aeff8ca' was successfully initialized, but failed to start. Please see the attached cause exception "class org.neo4j.driver.internal.cluster.RoutingTableHandlerImpl can not implement org.neo4j.driver.internal.cluster.RoutingTableHandler, because it is not an interface (org.neo4j.driver.internal.cluster.RoutingTableHandler is in unnamed module of loader '".
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:463) ~[neo4j-common-4.3.2.jar:4.3.2]
	at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:110) ~[neo4j-common-4.3.2.jar:4.3.2]
	at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.startDatabaseServer(DatabaseManagementServiceFactory.java:205) [neo4j-4.3.2.jar:4.3.2]
	at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.build(DatabaseManagementServiceFactory.java:170) [neo4j-4.3.2.jar:4.3.2]
	at com.neo4j.server.enterprise.EnterpriseManagementServiceFactory.createManagementService(EnterpriseManagementServiceFactory.java:38) [neo4j-enterprise-4.3.2.jar:4.3.2]
	at com.neo4j.server.enterprise.EnterpriseBootstrapper.createNeo(EnterpriseBootstrapper.java:20) [neo4j-enterprise-4.3.2.jar:4.3.2]
	at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:134) [neo4j-4.3.2.jar:4.3.2]
	at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:90) [neo4j-4.3.2.jar:4.3.2]
	at com.neo4j.server.enterprise.EnterpriseEntryPoint.main(EnterpriseEntryPoint.java:24) [neo4j-enterprise-4.3.2.jar:4.3.2]
Caused by: java.lang.IncompatibleClassChangeError: class org.neo4j.driver.internal.cluster.RoutingTableHandlerImpl can not implement org.neo4j.driver.internal.cluster.RoutingTableHandler, because it is not an interface (org.neo4j.driver.internal.cluster.RoutingTableHandler is in unnamed module of loader '
	at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[?:?]
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[?:?]
	at jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800) ~[?:?]
	at jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698) ~[?:?]
	at jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621) ~[?:?]
	at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579) ~[?:?]
	at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:576) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
	at org.neo4j.procedure.impl.ProcedureJarLoader$1.fetchNextOrNull(ProcedureJarLoader.java:168) ~[neo4j-procedure-4.3.2.jar:4.3.2]
	at org.neo4j.procedure.impl.ProcedureJarLoader$1.fetchNextOrNull(ProcedureJarLoader.java:146) ~[neo4j-procedure-4.3.2.jar:4.3.2]
	at org.neo4j.collection.AbstractPrefetchingRawIterator.peek(AbstractPrefetchingRawIterator.java:50) ~[neo4j-collections-4.3.2.jar:4.3.2]
	at org.neo4j.collection.AbstractPrefetchingRawIterator.hasNext(AbstractPrefetchingRawIterator.java:36) ~[neo4j-collections-4.3.2.jar:4.3.2]
	at org.neo4j.procedure.impl.ProcedureJarLoader.loadProcedures(ProcedureJarLoader.java:119) ~[neo4j-procedure-4.3.2.jar:4.3.2]
	at org.neo4j.procedure.impl.ProcedureJarLoader.loadProceduresFromDir(ProcedureJarLoader.java:96) ~[neo4j-procedure-4.3.2.jar:4.3.2]
	at org.neo4j.procedure.impl.GlobalProceduresRegistry.start(GlobalProceduresRegistry.java:383) ~[neo4j-procedure-4.3.2.jar:4.3.2]
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:442) ~[neo4j-common-4.3.2.jar:4.3.2]
	... 8 more
2021-08-25 16:27:30.464+0000 INFO  [o.n.g.f.DatabaseManagementServiceFactory] Shutdown started

Some key lines from my conf file is:


# Whether requests to Neo4j are authenticated.
# To disable authentication, uncomment this line
dbms.security.auth_enabled=true


#*****************************************************************
# Network connector configuration
#*****************************************************************

# With default configuration Neo4j only accepts local connections.
# To accept non-local connections, uncomment this line:
dbms.default_listen_address=0.0.0.0

# You can also choose a specific network interface, and configure a non-default
# port for each connector, by setting their individual listen_address.

# The address at which this server can be reached by its clients. This may be the server's IP address or DNS name, or
# it may be the address of a reverse proxy which sits in front of the server. This setting may be overridden for
# individual connectors below.
#dbms.default_advertised_address=localhost

# You can also choose a specific advertised hostname or IP address, and
# configure an advertised port for each connector, by setting their
# individual advertised_address.

# By default, encryption is turned off.
# To turn on encryption, an ssl policy for the connector needs to be configured
# Read more in SSL policy section in this file for how to define a SSL policy.

# Bolt connector
dbms.connector.bolt.enabled=true
#dbms.connector.bolt.tls_level=DISABLED
#dbms.connector.bolt.listen_address=:7687
#dbms.connector.bolt.advertised_address=:7687

# HTTP Connector. There can be zero or one HTTP connectors.
dbms.connector.http.enabled=true
#dbms.connector.http.listen_address=:7474
#dbms.connector.http.advertised_address=:7474

# HTTPS Connector. There can be zero or one HTTPS connectors.
dbms.connector.https.enabled=false
#dbms.connector.https.listen_address=:7473
#dbms.connector.https.advertised_address=:7473

# Cluster Routing Connector. Enables the opening of an additional port to allow
# for internal communication using the same security configuration as CLUSTER
#dbms.routing.enabled=false

# Customize the listen address and advertised address used for the routing connector.
#dbms.routing.listen_address=0.0.0.0:7688
#dbms.routing.advertised_address=:7688

# Number of Neo4j worker threads.
#dbms.threads.worker_count

# Bolt SSL configuration
#dbms.ssl.policy.bolt.enabled=true
#dbms.ssl.policy.bolt.base_directory=certificates/bolt
#dbms.ssl.policy.bolt.private_key=private.key
#dbms.ssl.policy.bolt.public_certificate=public.crt
#dbms.ssl.policy.bolt.client_auth=NONE

# Https SSL configuration
#dbms.ssl.policy.https.enabled=true
#dbms.ssl.policy.https.base_directory=certificates/https
#dbms.ssl.policy.https.private_key=private.key
#dbms.ssl.policy.https.public_certificate=public.crt
#dbms.ssl.policy.https.client_auth=NONE

# Cluster SSL configuration
#dbms.ssl.policy.cluster.enabled=true
#dbms.ssl.policy.cluster.base_directory=certificates/cluster
#dbms.ssl.policy.cluster.private_key=private.key
#dbms.ssl.policy.cluster.public_certificate=public.crt

#*****************************************************************
# Causal Clustering Configuration
#*****************************************************************

# Uncomment and specify these lines for running Neo4j in Causal Clustering mode.
# See the Causal Clustering documentation at https://neo4j.com/docs/ for details.

# Database mode
# Allowed values:
# CORE - Core member of the cluster, part of the consensus quorum.
# READ_REPLICA - Read replica in the cluster, an eventually-consistent read-only instance of the database.
# To operate this Neo4j instance in Causal Clustering mode as a core member, uncomment this line:
#dbms.mode=CORE

# Expected number of Core servers in the cluster at formation
#causal_clustering.minimum_core_cluster_size_at_formation=3

# Minimum expected number of Core servers in the cluster at runtime.
#causal_clustering.minimum_core_cluster_size_at_runtime=3

# A comma-separated list of the address and port for which to reach all other members of the cluster. It must be in the
# host:port format. For each machine in the cluster, the address will usually be the public ip address of that machine.
# The port will be the value used in the setting "causal_clustering.discovery_listen_address".
#causal_clustering.initial_discovery_members=localhost:5000,localhost:5001,localhost:5002

# Host and port to bind the cluster member discovery management communication.
# This is the setting to add to the collection of address in causal_clustering.initial_core_cluster_members.
# Use 0.0.0.0 to bind to any network interface on the machine. If you want to only use a specific interface
# (such as a private ip address on AWS, for example) then use that ip address instead.
# If you don't know what value to use here, use this machines ip address.
#causal_clustering.discovery_listen_address=:5000
#********************************************************************
# Other Neo4j system properties
#********************************************************************
apoc.export.file.enabled=true
dbms.security.procedures.unrestricted=jwt.security.*,apoc.*,gds.*,gen-12.*
#dbms.security.procedures.allowlist=jwt.security.*,gds.*,apoc.*, gen-12.*
#Comma separated list of JAXRS packages containing JAXRS Resource, one package name for each mountpoint.
#dbms.unmanaged_extension_classes=org.neo4j.genealogy-01

dbms.checkpoint.interval.time=30s
dbms.checkpoint.interval.tx=1
dbms.tx_log.rotation.retention_policy=false
dbms.tx_log.rotation.size=1M
dbms.transaction.timeout=30m
1 REPLY 1

genealogy
Graph Buddy

The solution for this is shown here:

pow.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--https://github.com/neo4j-examples/neo4j-procedure-template/blob/4.2/pom.xml#L24-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>wai.neo4j.gen</groupId>
    <artifactId>wai.neo4j.gen</artifactId>
    <version>1.2</version>
    <packaging>jar</packaging>
    <name>gen</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <neo4j.version>4.2.6</neo4j.version>
        <junit-jupiter.version>5.7.0</junit-jupiter.version>
        <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <assertj.version>3.18.1</assertj.version>
   </properties>

    <dependencies>
<!--necessary to start neo4j-->
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <!--<version>4.2.7</version>-->
            <version>4.3.0</version>
            <scope>provided</scope> 
        </dependency>
        <!--drivers in plugins must be the same-->
         <dependency>
            <groupId>org.neo4j.driver</groupId>
            <artifactId>neo4j-java-driver</artifactId>
            <version>4.3.0</version>
            <scope>provided</scope> 
        </dependency>
        <dependency>
            <groupId>org.neo4j.test</groupId>
            <artifactId>neo4j-harness</artifactId>
            <version>${neo4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--<dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>procedure-compiler</artifactId>
            <version>4.3.3</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>-->
    </dependencies>
    
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
      </plugin>
  
      <plugin>
        <!-- This generates a jar-file with our procedure code,
             plus any dependencies marked as `compile` scope.
             This should then be deployed in the `plugins` directory
             of each Neo4j instance in your deployment.
             After a restart, the procedure is available for calling. -->
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.7.1</version>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <!--https://stackoverflow.com/questions/25842559/valid-jar-signature-for-javafx-projects-->
          <excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The user defined function

/**
 * Copyright 2020 
 * David A Stumpf, MD, PhD
 * Who Am I -- Graphs for Genealogists
 * Woodstock, IL 60098 USA
 */
package gen;
    import org.neo4j.driver.AuthTokens;
    import org.neo4j.driver.Driver;
    import org.neo4j.driver.GraphDatabase;
    import org.neo4j.driver.Result;
    import org.neo4j.driver.Session;    
    import org.neo4j.driver.SessionConfig;
    import org.neo4j.driver.Transaction;
    import org.neo4j.driver.TransactionWork;
    import org.neo4j.driver.AccessMode;
    import org.neo4j.driver.net.ServerAddress;
   
    import org.neo4j.procedure.Name;
    import org.neo4j.procedure.UserFunction;
    import org.neo4j.procedure.Description;
  
            
    import static org.neo4j.driver.Values.parameters;
      
    public class mrca1 {          
        @UserFunction
        @Description("Input 2 RNs and get list of MRCAs")
        
    public String mrca(
        @Name("rn1") 
            Long rn1,
        @Name("rn2") 
            Long rn2,
              @Name("db") 
            String db
  )
    {
        
        { 
        String r =mrca_qry(rn1,rn2,db);
        return r;
            }
     }
   
    public String mrca_qry(long rn1, long rn2,String db) 
    {
    
        String qrystr = "match (p1:Person{RN:" + rn1 + "})-[r1:father|mother*0..15]->(mrca:Person)<-[r2:father|mother*0..15]-(p2:Person{RN:" + rn2 + "}) return mrca.fullname + ' [' + mrca.RN + '] (' + left(mrca.BD,4) +'-' + left(mrca.DD,4) +')'" ;
        Driver driver;
        driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "cns105" ) );
        driver.session(SessionConfig.builder().withDefaultAccessMode(AccessMode.READ).build());
        Session session = driver.session() ;
        try ( Session java_session = driver.session(SessionConfig.forDatabase(db)) )
        { 
            String javasession = java_session.writeTransaction(new TransactionWork<String>()
            {
                @Override
                public String execute( Transaction tx )
                {
                    Result rslt = tx.run( qrystr,
                            parameters( "message", qrystr ) );

                    
                    String output = "";
                        while (rslt.hasNext())
                        { 
                            output = output + rslt.next().values().toString() + "\n\r";
                        
                        }
	                return output;
                            
                    
                }
            } );
      return javasession;
        }
    }

}