Announcement Announcement Module
Collapse
No announcement yet.
Neo4j Cross-Store - SQL DB empty, no error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neo4j Cross-Store - SQL DB empty, no error

    Hi at all,

    I use Neo4j and the Neo4JTemplate to persist my Data.
    I have a class named File. I would like to store the bytes field in an extra SQLite database (or all fields). Bellow you can see my configuration and classes.
    If I save my File I get no errors but the database is still empty.
    Maybe I forgot one statement or something. I hope you can help me.

    Thanks,

    Christina

    application.xml
    Code:
    <?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 />
    
    	<neo4j:repositories base-package="de.mocta.io.persistence" />
    
    	<context:component-scan base-package="de.mocta.io.persistence" />
    
    	<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
    		destroy-method="shutdown" scope="singleton">
    		<constructor-arg index="0" value="../../db/mocta" />
    	</bean>
    
    	<bean
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    		id="entityManagerFactory">
    		<property name="dataSource">
    			<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    				<property name="driverClassName" value="org.sqlite.JDBC" />
    				<property name="url" value="jdbc:sqlite:../../db/mocta-sql.db" />				
    			</bean>
    		</property>
    		<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
    	</bean>
    	
    	<neo4j:config graphDatabaseService="graphDatabaseService"/>
    
    	<bean id="transactionManager"
    		class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
    		<constructor-arg ref="graphDatabaseService" />
    	</bean>
    
    	<tx:annotation-driven transaction-manager="transactionManager" />
    
    </beans>

    My persistence.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
     http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    	version="2.0">
    	<persistence-unit name="graphRelational"
    		transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
            <class>de.mocta.io.persistence.domain.File</class>
    		<properties>
                <property name="hibernate.dialect" value="de.mocta.io.sqlite.SQLiteDialect"/>
                 <property name="hibernate.hbm2ddl.auto" value="update"/>
               </properties>
    	</persistence-unit>
    </persistence>
    My pom.xml
    Code:
    <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>
    	<parent>
    		<groupId>de</groupId>
    		<artifactId>mocta</artifactId>
    		<version>0.0.1-SNAPSHOT</version>
    	</parent>
    	<groupId>de.mocta</groupId>
    	<artifactId>io</artifactId>
    	<properties>
    		<spring.version>3.1.2.RELEASE</spring.version>
    		<spring-data.version>2.0.1.RELEASE</spring-data.version>
    		<neo4j.version>1.6.2</neo4j.version>
    		<slf4j.version>1.7.1</slf4j.version>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<spring-security.version>3.1.0.RELEASE</spring-security.version>
    	</properties>
    	...
     	<dependencies>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-core</artifactId>
    			<version>${spring.version}</version>
    			<exclusions>
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-core</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-aop</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.data</groupId>
    			<artifactId>spring-data-neo4j</artifactId>
    			<version>${spring-data.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-tx</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-beans</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>3.5.5-Final</version>
            </dependency>
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>3.5.5-Final</version>
                <exclusions>
                    <exclusion>
                        <groupId>cglib</groupId>
                        <artifactId>cglib</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>dom4j</groupId>
                        <artifactId>dom4j</artifactId>
                    </exclusion>
                </exclusions>
            </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.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>4.1.0.Final</version>
                <exclusions>
                    <exclusion>
                        <groupId>javax.xml.bind</groupId>
                        <artifactId>jaxb-api</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.sun.xml.bind</groupId>
                        <artifactId>jaxb-impl</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        <dependency>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>1.0.0.GA</version>
            </dependency>
        <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib-nodep</artifactId>
                <version>2.2</version>
            </dependency>
        <dependency>
                <groupId>javax.transaction</groupId>
                <artifactId>jta</artifactId>
                <version>1.1</version>
            </dependency>
        <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
        <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${spring.version}</version>
            </dependency>
        <dependency>
                <groupId>commons-pool</groupId>
                <artifactId>commons-pool</artifactId>
                <version>1.5.4</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.3</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>commons-pool</groupId>
                        <artifactId>commons-pool</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>xerces</groupId>
                        <artifactId>xerces</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>xerces</groupId>
                        <artifactId>xercesImpl</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>xml-apis</groupId>
                        <artifactId>xml-apis</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
     		<dependency>
     			<groupId>org.xerial</groupId>
     			<artifactId>sqlite-jdbc</artifactId>
     			<version>3.7.2</version>
     		</dependency>
     		<dependency>
     			<groupId>org.springframework.data</groupId>
     			<artifactId>spring-data-neo4j-cross-store</artifactId>
     			<version>${spring-data.version}</version>
     		</dependency>
     		<dependency>
     			<groupId>org.neo4j</groupId>
     			<artifactId>neo4j-cypher</artifactId>
     			<version>${neo4j.version}</version>
     		</dependency>
     	</dependencies>
    </project>

  • #2
    And the other source-code:

    Class of File
    Code:
    import java.io.Serializable;
    import javax.persistence.*;
    import org.springframework.data.annotation.Transient;
    import org.springframework.data.neo4j.annotation.*;
    import org.springframework.data.neo4j.support.index.IndexType;
    
    @Entity
    @Table(name = "Attachment")
    @NodeEntity(partial = true)
    public class File implements Serializable {
    
    	@GraphId @Id  @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id")
    	private Long id;
    	
    	@Transient @GraphProperty @Indexed(indexName="name",indexType=IndexType.FULLTEXT)
    	private String name;
    	@Transient @GraphProperty
    	private String size;
    	@Transient @GraphProperty @Indexed(indexName="hash",indexType=IndexType.FULLTEXT)
    	private String hash;
    	@Transient @GraphProperty
    	private String hashType;
    	@Transient @GraphProperty @Indexed(indexName="format",indexType=IndexType.FULLTEXT)
    	private String format;
    	@Column(name = "bytes")
    	private byte[] bytes;
    	
    	
    // Getter + Setter + Constructor
    
    }

    Code:
    @Service
    public class PersistenceManager {
    	
    	@Autowired
    	private ApplicationPersistenceMapper persistence;
    		
    	
    	@Transactional
    	public void saveFile(File f) {
    		persistence.mapFile(f);
    	}

    Persistence-Class (saves the file)
    Code:
    @Service
    public class ApplicationPersistenceMapper {
    
    @Autowired
    	private Neo4jTemplate template;
    ...
    private File mapFile(File f) {
    		if (f == null)
    			return null;
    		f = template.save(f);
    		return f;
    }
    ...

    Comment


    • #3
      Originally posted by wer1 View Post
      And the other source-code:

      Class of File
      Code:
      import java.io.Serializable;
      import javax.persistence.*;
      import org.springframework.data.annotation.Transient;
      import org.springframework.data.neo4j.annotation.*;
      import org.springframework.data.neo4j.support.index.IndexType;
      
      @Entity
      @Table(name = "Attachment")
      @NodeEntity(partial = true)
      public class File implements Serializable {
      
      	@GraphId @Id  @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id")
      	private Long id;
      Could you try with the @GraphId and @Id on separate fields? Im not sure what happens when you share - Neo4j will insist on generating the id for you.

      Regards,

      Lasse

      Comment


      • #4
        Thanks for your reply.
        I tried to use separate fields but there is no difference in the database.
        Last edited by wer1; Oct 24th, 2012, 04:14 PM.

        Comment


        • #5
          No ideas? can nobody help me?

          Comment


          • #6
            Maybe someone can give me a full example on how to persist data in a cross store.

            Comment


            • #7
              Christina,

              There is an example here: https://github.com/SpringSource/spri...aurants-social

              Also, would it be possible to share your project on e.g. GitHub so we can use that to reproduce the problem?

              Thanks,

              Lasse

              Comment


              • #8
                Christina,

                I sat down and did a from-scratch example of cross-store persistence, please find it here:

                https://github.com/lassewesth/crossstore

                I have not added indexes, and also want to try adding spatial stuff later. But as a start, does it help?

                AspectJ is a bit tricky to get to work with Maven, not sure what I am ding wrong there. But when I open the project in IntelliJ it seems to work.

                Regards,

                Lasse

                Comment


                • #9
                  Thanks for your help. Not I got it. The only problem is that all attributes of the "File"-class are generated and saved in the sql database. Any ideas for this?

                  Comment


                  • #10
                    Does anybody know how to delete the entries in the jpa cross store? I delete my nodes in the graph database with "template.delete()" / "repository.delete()". I don't want to delete all entries.

                    Comment

                    Working...
                    X