Проблема взаимоотношений в neo4j.ogm с использованием приложения Spring Boot

В моем проекте я использую org.neo4j.ogm с весенней загрузкой. Пока я пытаюсь создать отношения, используя @RelationshipEntity, это означает, что они будут созданы успешно. Но он не поддерживает несколько к одному отношению.

Здесь я создаю отношение Blueprint к ScTaxonomy в отношении RELATED_TO_ScTaxonomy. И я хочу добавить свойства отношений для класса catalogueBlueprint.

Я имею в виду, что Blueprint-(RELATED_TO_ScTaxonomy)-ScTaxonomy со значениями класса catalogueBlueprint был сохранен в RELATED_TO_ScTaxonomy.

как только я перезапущу службу, я создам новое соединение, означающее, что уже созданные отношения будут потеряны, и будут сохранены только вновь созданные отношения.

Я использую запрос для

package nuclei.domain;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.neo4j.ogm.annotation.Relationship;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Blueprint extends Entity {

	private String blueprint;
	private String onIaas;
	private String script;

	private String isDeleted;

	@Relationship(type = "iaaSTemplate", direction = Relationship.INCOMING)
	IaaSTemplate iaaSTemplate;

	@Relationship(type = "iaasParameters")
	List<IaasParameters> iaasParameters;

	@Relationship(type = "tasks")
	List<Tasks> tasks;

	@Relationship(type = "RELATED_TO_ScTaxonomy")
	@JsonIgnore
    public List<CatalogueBlueprint> relations;
	
	
	public Blueprint() {
		iaaSTemplate = new IaaSTemplate();
		iaasParameters = new ArrayList<IaasParameters>();
		tasks = new ArrayList<Tasks>();
		relations = new ArrayList<CatalogueBlueprint>();
	}
	
	 public void addRelation(ScTaxonomy scTaxonomyRelation,CatalogueBlueprint catalogueBlueprint) {
		 catalogueBlueprint.blueprintRelation = this;
		 catalogueBlueprint.scTaxonomyRelation = scTaxonomyRelation;
		 
		 relations.add(catalogueBlueprint);
	/*	 relations.setCatalogueBlueprintId(catalogueBlueprint.getCatalogueBlueprintId());
		 relations.setOnIaas(catalogueBlueprint.getOnIaas());
		 relations.setScript(catalogueBlueprint.getScript());
		 relations.setX_axis(catalogueBlueprint.getX_axis());
		 relations.setY_axis(catalogueBlueprint.getY_axis());
		 relations.setStep(catalogueBlueprint.getStep());
		 relations.setIsDeleted(catalogueBlueprint.getIsDeleted());*/
		 
	     scTaxonomyRelation.relations.add(catalogueBlueprint);
	    }

	public Blueprint(String blueprint, String onIaas, String script,
			String isDeleted) {
		this.blueprint = blueprint;
		this.onIaas = onIaas;
		this.script = script;
		this.isDeleted = isDeleted;
	}

	public String getBlueprint() {
		return blueprint;
	}

	public void setBlueprint(String blueprint) {
		this.blueprint = blueprint;
	}

	public String getOnIaas() {
		return onIaas;
	}

	public void setOnIaas(String onIaas) {
		this.onIaas = onIaas;
	}

	public String getScript() {
		return script;
	}

	public void setScript(String script) {
		this.script = script;
	}

	public String getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}

	public List<IaasParameters> getIaasParameters() {
		return iaasParameters;
	}

	public void setIaasParameters(List<IaasParameters> iaasParameters) {
		this.iaasParameters = iaasParameters;
	}

	public List<Tasks> getTasks() {
		return tasks;
	}

	public void setTasks(List<Tasks> tasks) {
		this.tasks = tasks;
	}

	public IaaSTemplate getIaaSTemplate() {
		return iaaSTemplate;
	}

	public void setIaaSTemplate(IaaSTemplate iaaSTemplate) {
		this.iaaSTemplate = iaaSTemplate;
	}

	public List<CatalogueBlueprint> getRelations() {
		return relations;
	}

	public void setRelations(List<CatalogueBlueprint> relations) {
		this.relations = relations;
	}

}

/**
 * 
 */
package nuclei.domain;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.neo4j.ogm.annotation.Relationship;

/**
 * @author Karthikeyan
 *
 */

public class ScTaxonomy extends Entity {

	private String taxName;	
	private String description;
	private String isDeleted;
	private String step;
	private String serviceCatalogueStep;	
	private String x_axis;
	private String y_axis;

	@Relationship(type = "RELATED_TO_ScTaxonomy", direction = "INCOMING")
    public List<CatalogueBlueprint> relations;
	
	public ScTaxonomy() {
		relations = new ArrayList<>();	
	}

	public ScTaxonomy(String taxName, String description, String isDeleted,String step,String serviceCatalogueStep,
			String x_axis,String y_axis) {
		this.taxName=taxName;
		this.description = description;		
		this.isDeleted = isDeleted;	
		this.step=step;
		this.serviceCatalogueStep=serviceCatalogueStep;
		this.x_axis=x_axis;
		this.y_axis=y_axis;
	}

	public String getTaxName() {
		return taxName;
	}

	public void setTaxName(String taxName) {
		this.taxName = taxName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}

	public String getStep() {
		return step;
	}

	public void setStep(String step) {
		this.step = step;
	}

	public String getServiceCatalogueStep() {
		return serviceCatalogueStep;
	}

	public void setServiceCatalogueStep(String serviceCatalogueStep) {
		this.serviceCatalogueStep = serviceCatalogueStep;
	}

	public String getX_axis() {
		return x_axis;
	}

	public void setX_axis(String x_axis) {
		this.x_axis = x_axis;
	}

	public String getY_axis() {
		return y_axis;
	}

	public void setY_axis(String y_axis) {
		this.y_axis = y_axis;
	}

	public List<CatalogueBlueprint> getRelations() {
		return relations;
	}

	public void setRelations(List<CatalogueBlueprint> relations) {
		this.relations = relations;
	}	
		
}

package nuclei.domain;

import java.util.List;

import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;

@RelationshipEntity(type="catalogueBlueprint")
public class CatalogueBlueprint extends Entity {

	private long catalogueBlueprintId;
	private String onIaas;
	private String script;
	private String x_axis;
	private String y_axis;
	private String step;
	private String isDeleted;

	@StartNode
    public  Blueprint blueprintRelation;
	
	@EndNode
	public ScTaxonomy scTaxonomyRelation;
	
	public CatalogueBlueprint() {
	
	}

	public CatalogueBlueprint(ScTaxonomy to,Blueprint from, String onIaas, String script,long catalogueBlueprintId,
			String isDeleted,String x_axis,String y_axis,String step) {
		
		this.scTaxonomyRelation=to;
		this.blueprintRelation=from;
		this.onIaas = onIaas;
		this.script = script;
		this.isDeleted = isDeleted;
		this.x_axis=x_axis;
		this.y_axis=y_axis;
		this.step=step;
		this.catalogueBlueprintId=catalogueBlueprintId;
	}

	public long getCatalogueBlueprintId() {
		return catalogueBlueprintId;
	}

	public void setCatalogueBlueprintId(long catalogueBlueprintId) {
		this.catalogueBlueprintId = catalogueBlueprintId;
	}

	public String getOnIaas() {
		return onIaas;
	}

	public void setOnIaas(String onIaas) {
		this.onIaas = onIaas;
	}

	public String getScript() {
		return script;
	}

	public void setScript(String script) {
		this.script = script;
	}

	public String getX_axis() {
		return x_axis;
	}

	public void setX_axis(String x_axis) {
		this.x_axis = x_axis;
	}

	public String getY_axis() {
		return y_axis;
	}

	public void setY_axis(String y_axis) {
		this.y_axis = y_axis;
	}

	public String getStep() {
		return step;
	}

	public void setStep(String step) {
		this.step = step;
	}

	public String getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}

	public ScTaxonomy getScTaxonomyRelation() {
		return scTaxonomyRelation;
	}

	public void setScTaxonomyRelation(ScTaxonomy scTaxonomyRelation) {
		this.scTaxonomyRelation = scTaxonomyRelation;
	}

	public Blueprint getBlueprintRelation() {
		return blueprintRelation;
	}

	public void setBlueprintRelation(Blueprint blueprintRelation) {
		this.blueprintRelation = blueprintRelation;
	}

}

/**
 * 
 */
package nuclei.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nuclei.domain.CatalogueBlueprint;
import nuclei.domain.IaaSTemplate;
import nuclei.domain.IaasParameters;
import nuclei.domain.ScTaxonomy;
import nuclei.domain.Tasks;
import nuclei.domain.Blueprint;
import nuclei.response.BlueprintMessage;
import nuclei.response.BlueprintsMessage;
import nuclei.response.CatalogueBlueprintMessage;
import nuclei.response.ResponseStatus;
import nuclei.response.ResponseStatusCode;
import nuclei.service.CatalogueBlueprintService;
import nuclei.service.MainService;
import nuclei.service.BlueprintService;
import nuclei.service.ScTaxonomyService;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.jersey.multipart.FormDataParam;

/**
 * @author Karthikeyan
 *
 */

// @RestController
@Controller
public class BlueprintController extends MainController<Blueprint> {

	@Autowired
	private CatalogueBlueprintService catalogueBlueprintService;
	
	@Autowired
	private ScTaxonomyService scTaxonomyService;
	
	@Autowired
	private BlueprintService blueprintService;


	//create scTaxonomy relation
		@RequestMapping(value = "/createScTaxonomyRelation", method = RequestMethod.POST)
		public @ResponseBody BlueprintMessage relationTest(
				@FormDataParam("ScTaxonomyId") String ScTaxonomyId,
				@FormDataParam("blueprintId") String blueprintId,
				@FormDataParam("catalogueBlueprintId") String catalogueBlueprintId,		
				@FormDataParam("onIaas") String onIaas,
				@FormDataParam("script") String script,
				@FormDataParam("step") String step,			
				@FormDataParam("x_axis") String x_axis,
				@FormDataParam("y_axis") String y_axis,
				final HttpServletResponse response) {
			
			ResponseStatus status = null;
			Long blueptId = Long.parseLong(blueprintId);
			Long taxonomyId = Long.parseLong(ScTaxonomyId);	
			List<CatalogueBlueprint> catalogueBPList =  new ArrayList<CatalogueBlueprint>();
			CatalogueBlueprint catalogueBP=new CatalogueBlueprint();
			Blueprint blueprint=null;		
			ScTaxonomy taxonomy = null;
			try {
				
				Long catalogueID=Long.parseLong(catalogueBlueprintId);
				taxonomy = scTaxonomyService.find(taxonomyId);
									
				blueprint=blueprintService.find(blueptId);
				
				catalogueBP.setBlueprintRelation(blueprint);
				catalogueBP.setScTaxonomyRelation(taxonomy);
				
				catalogueBP.setOnIaas(onIaas);
				catalogueBP.setCatalogueBlueprintId(catalogueID);
				catalogueBP.setScript(script);	
				catalogueBP.setStep(step);			
				catalogueBP.setX_axis(x_axis);
				catalogueBP.setY_axis(y_axis);
				catalogueBP.setIsDeleted("0");		
				
				catalogueBPList.add(catalogueBP);					
						
				blueprint.addRelation(taxonomy, catalogueBP);
				
				super.create(blueprint);
				//super.update(blueptId, blueprint);
			
				status = new ResponseStatus(ResponseStatusCode.STATUS_OK, "SUCCESS");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return new BlueprintMessage(status, blueprint);
		}

	@Override
	public MainService<Blueprint> getService() {
		return blueprintService;
	}

	
}


person Karthikeyan Velmurugan    schedule 21.08.2015    source источник
comment
это много кода для переваривания. Не могли бы вы публиковать только соответствующие разделы   -  person e4c5    schedule 21.08.2015
comment
Как я могу использовать RelationshipEntity для neo4j.ogm с приложением весенней загрузки. используя StartNode и EndNode   -  person Karthikeyan Velmurugan    schedule 21.08.2015
comment
Я предполагаю, что вам удалось обновиться до 4.0.0.RC2? В предыдущих версиях были проблемы с объектами отношений.   -  person Luanne    schedule 21.08.2015
comment
Я пробую это также, как только я обновляю версию до 4.0.0.RC2, это означает, что она показывает некоторую ошибку, пока я запускаю проект.   -  person Karthikeyan Velmurugan    schedule 21.08.2015
comment
Ошибка была java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories.repositoryBaseClass()   -  person Karthikeyan Velmurugan    schedule 21.08.2015
comment
Какая версия spring-data-commons используется (с зависимостью: дерево).   -  person Luanne    schedule 21.08.2015
comment
В частности, я никого не использую. Но в SDN 4.0.0.RC2 есть spring-data-commons. Поэтому я использую только это.   -  person Karthikeyan Velmurugan    schedule 22.08.2015
comment
Его также могла потянуть какая-то другая зависимость. Пожалуйста, проверьте зависимость mvn:tree   -  person Luanne    schedule 25.08.2015
comment
Теперь я удалил все зависимости и добавил обновленные версии для всех зависимостей, тогда ошибка не отображалась, и приложение работало успешно.   -  person Karthikeyan Velmurugan    schedule 28.08.2015


Ответы (1)


Я удалил все зависимости и добавил обновленные версии для всех зависимостей, после чего ошибка не отображалась, и приложение работало успешно.

person Karthikeyan Velmurugan    schedule 28.08.2015