0

在我的项目中,我将 org.neo4j.ogm 与 spring boot 一起使用。当我尝试使用 @RelationshipEntity 创建关系时,意味着它将成功创建。但它不支持多对一关系。

在这里,我在 RELATED_TO_ScTaxonomy 上的关系中创建 Blueprint 与 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;
	}

	
}

4

1 回答 1

0

我删除了所有依赖项并为所有依赖项添加了更新版本,然后错误未显示并且应用程序成功运行。

于 2015-08-28T04:01:15.820 回答