spring data neo4j advanced mapping throws exception "com.baidu.rigel.neo4jTest.domain.World cannot be cast to org.springframework.data.neo4j.aspects.core.NodeBacked"

34 views
Skip to first unread message

beyon...@gmail.com

unread,
Jun 10, 2014, 8:35:46 AM6/10/14
to ne...@googlegroups.com
hi,
    i'm green hand. I want to compare advanced mapping  with simple mapping way. But when call persist method, throws a exception as following
    Exception in thread "main" java.lang.ClassCastException: com.baidu.rigel.neo4jTest.domain.World cannot be cast to org.springframework.data.neo4j.aspects.core.NodeBacked
    at com.baidu.rigel.neo4jTest.Main.createWorld(Main.java:59)
    at com.baidu.rigel.neo4jTest.Main.main(Main.java:21)
   
   My main code as following :
    public static void createWorld() {

            World world = new World("Jupiter", 63);
            ((NodeBacked)world).persist();
    }
  The question bothers me the whole day~~~Any help will be greatful. Thanks.
PS:
   applicationcontext.xml as follow:
   <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/neo4j
        http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:spring-configured/>
    <context:annotation-config/>




    <context:component-scan base-package="com.baidu.rigel.neo4jTest"/>

    <neo4j:repositories base-package="com.baidu.rigel.neo4jTest.repositories"/>

    <bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase" scope="singleton">
       <!--  <constructor-arg index="0" value="http://yf-rd-crm-cdc-db05.yf01.baidu.com:8474/db/data" /> -->
          <constructor-arg index="0" value="http://localhost:7474/db/data" />
    </bean>
    <neo4j:config graphDatabaseService="graphDatabaseService"  base-package="com.baidu.rigel.neo4jTest.domain"/>

    <bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager">
            <bean id="jotm"
                class="org.springframework.data.neo4j.transaction.JotmFactoryBean" />
        </property>
    </bean>

   <tx:annotation-driven mode="aspectj"
        transaction-manager="transactionManager" />

</beans>

    My pom.xml as following:
    <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>spring-data-neo4j-showcase</groupId>
    <artifactId>spring-data-neo4j-showcase</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <spring.data.neo4j.version>3.1.0.RELEASE</spring.data.neo4j.version>
        <neo4j.kernel.version>2.0.1</neo4j.kernel.version>
        <spring.core.version>3.2.8.RELEASE</spring.core.version>
        <neo4j.cypher.dsl.version>2.0.1</neo4j.cypher.dsl.version>
        <maven-compiler-plugin.version>2.1</maven-compiler-plugin.version>
        <spring.data.common.version>1.9.0.BUILD-SNAPSHOT</spring.data.common.version>
        <aspectj.version>1.7.4</aspectj.version>
    </properties>
    <repositories>
        <repository>
            <id>spring-maven-release</id>
            <name>Spring Maven Release Repository</name>
            <url>http://maven.springframework.org/release</url>
        </repository>
        <repository>
            <id>spring-maven-snapshot</id>
            <name>Spring Maven Snapshot Repository</name>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://maven.springframework.org/snapshot</url>
        </repository>
        <repository>
            <id>spring-maven-milestone</id>
            <name>Spring Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
        </repository>
        <repository>
            <id>neo4j-release-repository</id>
            <name>Neo4j Maven 2 release repository</name>
            <url>http://m2.neo4j.org/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>neo4j-snapshot-repository</id>
            <name>Neo4j Maven 2 snapshot repository</name>
            <url>http://m2.neo4j.org/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-maven-release</id>
            <name>Spring Maven Release Repository</name>
            <url>http://maven.springframework.org/release</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-maven-milestone</id>
            <name>Spring Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
        </pluginRepository>
    </pluginRepositories>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.core.version}</version>
        </dependency>
        <!-- <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId>
            <version>${spring.data.common.version}</version> </dependency> -->

        <!-- Spring Data Neo4j -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>${spring.data.neo4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.core.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j-aspects</artifactId>
            <version>${spring.data.neo4j.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate.javax.persistence</groupId>
                    <artifactId>hibernate-jpa-2.0-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j-rest</artifactId>
            <version>${spring.data.neo4j.version}</version>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.core.version}</version>

        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>${neo4j.kernel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher</artifactId>
            <version>${neo4j.kernel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-kernel</artifactId>
            <version>${neo4j.kernel.version}</version>
            <scope>test</scope>
            <type>test-jar</type>
        </dependency>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-dsl</artifactId>
            <version>${neo4j.cypher.dsl.version}</version>
        </dependency>
        <!-- <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j-ha</artifactId>
            <version>${neo4j.kernel.version}</version> </dependency> <dependency> <groupId>org.neo4j</groupId>
            <artifactId>neo4j-management</artifactId> <version>${neo4j.kernel.version}</version>
            </dependency> -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.core.version}</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>

    </dependencies>

    <build>
         <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>

                <!--This plugin's configuration is used to store Eclipse m2e settings
                    only. It has no influence on the Maven build itself. -->
                <!-- <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>aspectj-maven-plugin</artifactId>
                                        <versionRange>[1.0,)</versionRange>
                                        <goals>
                                            <goal>test-compile</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin> -->
                 <!-- the eclipse plugin interacts with the aspectj-maven-plugin
            BUT ONLY if the ajdtVersion config value is set (remove it and it won't) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                <!-- The ajdtVersion configuration parameter is optional. The valid values are none, 1.4, and 1.5. none indicates that AJDT should not be enabled even though Aspectj is enabled in maven. 1.4 generates the org.eclipse.ajdt.ui.prefs file in the .settings directory. 1.5 (or later) includes the configuration into the .classpath file and is the default value. -->
                    <ajdtVersion>1.5</ajdtVersion>
                    <additionalProjectnatures>
                        <projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
                        <projectnature>org.eclipse.jdt.core.javanature</projectnature>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                </configuration>
            </plugin>
                <plugin>
                    <!-- required to resolve aspectj-enhanced class features -->
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.4</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjrt</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjtools</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <outxml>true</outxml>
                        <aspectLibraries>
                            <aspectLibrary>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-aspects</artifactId>
                            </aspectLibrary>
                            <aspectLibrary>
                                <groupId>org.springframework.data</groupId>
                                <artifactId>spring-data-neo4j-aspects</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>


                </plugin>
            </plugins>
         </pluginManagement>
    </build>

</project>

Michael Hunger

unread,
Jun 10, 2014, 1:32:27 PM6/10/14
to ne...@googlegroups.com
Is this in the hello-world test-project or in a project you could share on github?

Thanks a lot

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jacklee tom

unread,
Aug 4, 2016, 2:21:58 AM8/4/16
to Neo4j
hi, i want to modify the source of the neo4j . i meet the same issue. 
Reply all
Reply to author
Forward
0 new messages