Spring - cross-reference data warehouse management

I want to use Postgres, MongoDB and Neo4j together in my application. I was able to configure all of them, but now each of my POJOs supports my graphNode, as well as the aspectJ document.

Is there a way to filter which POJOs are supported only using graphNodes and which are document-only?

I have a problem saving POJOs when I do this more than two times [sic!] In one request, and I can see in the log that mongo and neo4j are trying to create many instances that cause some kind of deadlock king.

Shortly speaking:

  • Is there a way to filter data mappings to configure pojo "A" to display RDBMS and graph (without a document) and pojo B by documents and graphs (without RDBMS).
  • Is there any sample for spring cross-repository application that more or less covers my problem?
  • Why can I save two instances of the pojo class in the controller one by one, but when the third instance is created, can I notice a dead end?

[EDIT]

What I noticed:

  • Mongo aspectj builder backs @Entity annotated POJOs and I don't know how to use @Entity to map POJOs for sleep mode, not MongoDB
  • The Neo4j related to freezing occurs only when connected via REST and sometimes occurs on the 3rd, sometimes on the 4th, and sometimes does not happen at all. See Initiating a controller for how to do this. I tried all the commented lines without success.
  • The transaction manager configuration must be located in the right place, otherwise the Neo4J configuration validation service will fail.

[/ EDIT]

I use:

  • Spring 3.0.5
  • SpringRoo 1.4
  • Spring -data 1.0
  • Postgres 9.0 + Hibernate 3.5.5
  • Neo4j 1.3 remotely
  • MongoDB 1.8.2 remotely
  • All databases are on the same remote computer and work fine

[EDIT]

POM fragments:

<properties> <roo.version>1.1.4.RELEASE</roo.version> <spring.version>3.0.5.RELEASE</spring.version> <aspectj.version>1.6.11</aspectj.version> <slf4j.version>1.6.1</slf4j.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring-security.version>3.0.5.RELEASE</spring-security.version> <jackson.version>1.8.0</jackson.version> <spring.data.mongodb.version>1.0.0.M2</spring.data.mongodb.version> <spring.data.graph.version>1.0.0.RELEASE</spring.data.graph.version> <spring.data.commons.version>1.0.0.RELEASE</spring.data.commons.version> </properties> ... <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j</artifactId> <version>${spring.data.graph.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb-cross-store</artifactId> <version>${spring.data.mongodb.version}</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>${spring.data.mongodb.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j-rest</artifactId> <version>${spring.data.graph.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons-core</artifactId> <version>${spring.data.commons.version}</version> <scope>compile</scope> </dependency> .... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.0</version> <dependencies> <!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --> <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</artifactId> </aspectLibrary> <aspectLibrary> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb-cross-store</artifactId> </aspectLibrary> </aspectLibraries> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

POJO:

 @NodeEntity @RooToString @RooJavaBean public class DElement { @Indexed private Long id; @RelatedTo(direction=Direction.BOTH, elementClass=DRegion.class, type="SUBELEMENT_OF") private Set<DElement> childElements = new HashSet<DElement>(); @Indexed(indexName = "delement-name", fulltext=true) private String name; @Transactional public void addChild(DElementchild child) { this.childElements.add(child); } } 

Controller (with download):

  @Controller @RequestMapping(value="/DElements") public class DElementsController { DElementRepository DElementRepository; GraphDatabaseContext gdbc; @Autowired public DElementsController(DElementRepository DElementRepository, GraphDatabaseContext gdbc) { this.DElementRepository = DElementRepository; this.gdbc = gdbc; this.initElements(); } @Transactional private void initElements() { try { DElementRepository.deleteAll(); } catch (Exception e) {} finally{} //Transaction txn = gdbc.beginTx(); referenceNode.createRelationshipTo(allElements.getPersistentState(), myRelation); DElement naElements = new DElement().persist(); naElements.setName("1"); allElements.addChild(naElements); DElement saElements = new DElement().persist(); saElements.setName("2"); allElements.addChild(saElements); DElement euElements = new DElement().persist(); euElements.setName("3"); allElements.addChild(euElements); DElement afElements = new DElement().persist(); afElements.setName("4"); allElements.addChild(afElements); DElement asElements = new DElement().persist(); asElements.setName("5"); allElements.addChild(asElements); DElement auElements = new DElement().persist(); auElements.setName("6"); allElements.addChild(auElements); //txn.success(); //txn.finish(); } } 

applicationContext.xml

 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xmlns:graph="http://www.springframework.org/schema/data/graph" xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/data/graph http://www.springframework.org/schema/data/graph/datagraph-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:property-placeholder location="classpath*:META-INF/spring/*.properties" /> <context:spring-configured /> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <context:component-scan base-package="com.foobar"> <context:exclude-filter expression=".*_Roo_.*" type="regex" /> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" /> </context:component-scan> <jee:jndi-lookup id="dataSource" jndi-name="jdbc/foobar" /> <mongo:mongo host="${foobar.mongodb.addr}" port="27017" /> <mongo:mapping-converter base-package="com.foobar.lib.model.mongo"/> <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databaseName" value="foobar" /> <constructor-arg name="defaultCollectionName" value="basecoll" /> </bean> <bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator" /> <!-- Mongo cross-store aspect config --> <bean class="org.springframework.data.persistence.document.mongo.MongoDocumentBacking" factory-method="aspectOf"> <property name="changeSetPersister" ref="mongoChangeSetPersister" /> </bean> <bean id="mongoChangeSetPersister" class="org.springframework.data.persistence.document.mongo.MongoChangeSetPersister"> <property name="mongoTemplate" ref="mongoTemplate" /> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown" > <constructor-arg index="0" value="c:/neo4j/data/foobar" /> </bean> <!-- REST DOESNT WORK FOR THE MOMENT <bean id="graphDatabaseService" class="org.springframework.data.graph.neo4j.rest.support.RestGraphDatabase"> <constructor-arg value="${foobar.neo4j.reststore}"/> </bean> --> <!-- <bean id="graphDatabaseContext" class="org.springframework.data.graph.neo4j.support.GraphDatabaseContext"> <property name="graphDatabaseService" ref="graphDatabaseService"/> </bean> --> <graph:repositories base-package="com.foobar.data.repositories.neo4j" graph-database-context-ref="graphDatabaseContext"/> <graph:config graphDatabaseService="graphDatabaseService" entityManagerFactory="entityManagerFactory" /> <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> </bean> </beans> 

[/ EDIT]

+4
source share
1 answer

Some general comments.

You only need to pass Spring Data Graph to the entityManagerFactory if you want to use Graph-JPA persistent storage. An example can be found here . If you do this, you must also enable the partial = true flag in your POJOs that you want to participate in setting up cross-storage.

Spring Graph Cross Data Warehouse and Spring Data MongoDB cross store work differently in the way they interact with JPA, SDG works with Graph POJO when saving or loading objects that they are (re) connected to their JPA object (via the @ field Id).

On the other hand, Spring Data MongoDB uses AspectJ to complement some EntityManager methods to use lifecycle events for the document database.

There is no history right now for integrating MongoDB and Neo4j. But since we, the projects that lead both projects, live in the same city and work closely together, I think this should be feasible.

It would be great if you could share your full project code with us, either on github (there can also be a private repo [my github id is "jexp", or by mail or Dropbox). So that we can dig right into it.

To your questions:

  • graph + rdmbs - all objects that have partial = true, and you must have @Entity annotations on your POJO
  • I'm not sure how mongo-cross-store is configured correctly.
  • usually, which must be configured through persistence.xml to which the objects are mapped.
  • i.e. perhaps we should develop a mechanism that says it sets up the persistence.xml file for each repository that wants to interact with EntityManager / JPA / RDMBS
  • is it possible that also works by defining two entity managers, one for the chart and the other for mongo?
  • you must first run it in neo4j native mode and then look at the remote server (REST) ​​later
  • you should probably upgrade Spring Data Graph to 1.1.M2, Neo4j to 1.4, and AspectJ to 1.6.12.M1

Please connect in person so that we can solve all problems and come to a good solution.

+4
source

All Articles