0
在我的項目中,我使用的是帶有spring啓動的org.neo4j.ogm。雖然我正在嘗試使用@RelationshipEntity創建關係,但意味着它會成功創建。但它不支持多對一的關係。neo4j.ogm使用彈簧啓動應用程序的關係問題
在這裏,我正在爲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 {
\t private String blueprint;
\t private String onIaas;
\t private String script;
\t private String isDeleted;
\t @Relationship(type = "iaaSTemplate", direction = Relationship.INCOMING)
\t IaaSTemplate iaaSTemplate;
\t @Relationship(type = "iaasParameters")
\t List<IaasParameters> iaasParameters;
\t @Relationship(type = "tasks")
\t List<Tasks> tasks;
\t @Relationship(type = "RELATED_TO_ScTaxonomy")
\t @JsonIgnore
public List<CatalogueBlueprint> relations;
\t
\t
\t public Blueprint() {
\t \t iaaSTemplate = new IaaSTemplate();
\t \t iaasParameters = new ArrayList<IaasParameters>();
\t \t tasks = new ArrayList<Tasks>();
\t \t relations = new ArrayList<CatalogueBlueprint>();
\t }
\t
\t public void addRelation(ScTaxonomy scTaxonomyRelation,CatalogueBlueprint catalogueBlueprint) {
\t \t catalogueBlueprint.blueprintRelation = this;
\t \t catalogueBlueprint.scTaxonomyRelation = scTaxonomyRelation;
\t \t
\t \t relations.add(catalogueBlueprint);
\t /* \t relations.setCatalogueBlueprintId(catalogueBlueprint.getCatalogueBlueprintId());
\t \t relations.setOnIaas(catalogueBlueprint.getOnIaas());
\t \t relations.setScript(catalogueBlueprint.getScript());
\t \t relations.setX_axis(catalogueBlueprint.getX_axis());
\t \t relations.setY_axis(catalogueBlueprint.getY_axis());
\t \t relations.setStep(catalogueBlueprint.getStep());
\t \t relations.setIsDeleted(catalogueBlueprint.getIsDeleted());*/
\t \t
\t scTaxonomyRelation.relations.add(catalogueBlueprint);
\t }
\t public Blueprint(String blueprint, String onIaas, String script,
\t \t \t String isDeleted) {
\t \t this.blueprint = blueprint;
\t \t this.onIaas = onIaas;
\t \t this.script = script;
\t \t this.isDeleted = isDeleted;
\t }
\t public String getBlueprint() {
\t \t return blueprint;
\t }
\t public void setBlueprint(String blueprint) {
\t \t this.blueprint = blueprint;
\t }
\t public String getOnIaas() {
\t \t return onIaas;
\t }
\t public void setOnIaas(String onIaas) {
\t \t this.onIaas = onIaas;
\t }
\t public String getScript() {
\t \t return script;
\t }
\t public void setScript(String script) {
\t \t this.script = script;
\t }
\t public String getIsDeleted() {
\t \t return isDeleted;
\t }
\t public void setIsDeleted(String isDeleted) {
\t \t this.isDeleted = isDeleted;
\t }
\t public List<IaasParameters> getIaasParameters() {
\t \t return iaasParameters;
\t }
\t public void setIaasParameters(List<IaasParameters> iaasParameters) {
\t \t this.iaasParameters = iaasParameters;
\t }
\t public List<Tasks> getTasks() {
\t \t return tasks;
\t }
\t public void setTasks(List<Tasks> tasks) {
\t \t this.tasks = tasks;
\t }
\t public IaaSTemplate getIaaSTemplate() {
\t \t return iaaSTemplate;
\t }
\t public void setIaaSTemplate(IaaSTemplate iaaSTemplate) {
\t \t this.iaaSTemplate = iaaSTemplate;
\t }
\t public List<CatalogueBlueprint> getRelations() {
\t \t return relations;
\t }
\t public void setRelations(List<CatalogueBlueprint> relations) {
\t \t this.relations = relations;
\t }
}
/**
*
*/
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 {
\t private String taxName; \t
\t private String description;
\t private String isDeleted;
\t private String step;
\t private String serviceCatalogueStep; \t
\t private String x_axis;
\t private String y_axis;
\t @Relationship(type = "RELATED_TO_ScTaxonomy", direction = "INCOMING")
public List<CatalogueBlueprint> relations;
\t
\t public ScTaxonomy() {
\t \t relations = new ArrayList<>(); \t
\t }
\t public ScTaxonomy(String taxName, String description, String isDeleted,String step,String serviceCatalogueStep,
\t \t \t String x_axis,String y_axis) {
\t \t this.taxName=taxName;
\t \t this.description = description; \t \t
\t \t this.isDeleted = isDeleted; \t
\t \t this.step=step;
\t \t this.serviceCatalogueStep=serviceCatalogueStep;
\t \t this.x_axis=x_axis;
\t \t this.y_axis=y_axis;
\t }
\t public String getTaxName() {
\t \t return taxName;
\t }
\t public void setTaxName(String taxName) {
\t \t this.taxName = taxName;
\t }
\t public String getDescription() {
\t \t return description;
\t }
\t public void setDescription(String description) {
\t \t this.description = description;
\t }
\t public String getIsDeleted() {
\t \t return isDeleted;
\t }
\t public void setIsDeleted(String isDeleted) {
\t \t this.isDeleted = isDeleted;
\t }
\t public String getStep() {
\t \t return step;
\t }
\t public void setStep(String step) {
\t \t this.step = step;
\t }
\t public String getServiceCatalogueStep() {
\t \t return serviceCatalogueStep;
\t }
\t public void setServiceCatalogueStep(String serviceCatalogueStep) {
\t \t this.serviceCatalogueStep = serviceCatalogueStep;
\t }
\t public String getX_axis() {
\t \t return x_axis;
\t }
\t public void setX_axis(String x_axis) {
\t \t this.x_axis = x_axis;
\t }
\t public String getY_axis() {
\t \t return y_axis;
\t }
\t public void setY_axis(String y_axis) {
\t \t this.y_axis = y_axis;
\t }
\t public List<CatalogueBlueprint> getRelations() {
\t \t return relations;
\t }
\t public void setRelations(List<CatalogueBlueprint> relations) {
\t \t this.relations = relations;
\t } \t
\t \t
}
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 {
\t private long catalogueBlueprintId;
\t private String onIaas;
\t private String script;
\t private String x_axis;
\t private String y_axis;
\t private String step;
\t private String isDeleted;
\t @StartNode
public Blueprint blueprintRelation;
\t
\t @EndNode
\t public ScTaxonomy scTaxonomyRelation;
\t
\t public CatalogueBlueprint() {
\t
\t }
\t public CatalogueBlueprint(ScTaxonomy to,Blueprint from, String onIaas, String script,long catalogueBlueprintId,
\t \t \t String isDeleted,String x_axis,String y_axis,String step) {
\t \t
\t \t this.scTaxonomyRelation=to;
\t \t this.blueprintRelation=from;
\t \t this.onIaas = onIaas;
\t \t this.script = script;
\t \t this.isDeleted = isDeleted;
\t \t this.x_axis=x_axis;
\t \t this.y_axis=y_axis;
\t \t this.step=step;
\t \t this.catalogueBlueprintId=catalogueBlueprintId;
\t }
\t public long getCatalogueBlueprintId() {
\t \t return catalogueBlueprintId;
\t }
\t public void setCatalogueBlueprintId(long catalogueBlueprintId) {
\t \t this.catalogueBlueprintId = catalogueBlueprintId;
\t }
\t public String getOnIaas() {
\t \t return onIaas;
\t }
\t public void setOnIaas(String onIaas) {
\t \t this.onIaas = onIaas;
\t }
\t public String getScript() {
\t \t return script;
\t }
\t public void setScript(String script) {
\t \t this.script = script;
\t }
\t public String getX_axis() {
\t \t return x_axis;
\t }
\t public void setX_axis(String x_axis) {
\t \t this.x_axis = x_axis;
\t }
\t public String getY_axis() {
\t \t return y_axis;
\t }
\t public void setY_axis(String y_axis) {
\t \t this.y_axis = y_axis;
\t }
\t public String getStep() {
\t \t return step;
\t }
\t public void setStep(String step) {
\t \t this.step = step;
\t }
\t public String getIsDeleted() {
\t \t return isDeleted;
\t }
\t public void setIsDeleted(String isDeleted) {
\t \t this.isDeleted = isDeleted;
\t }
\t public ScTaxonomy getScTaxonomyRelation() {
\t \t return scTaxonomyRelation;
\t }
\t public void setScTaxonomyRelation(ScTaxonomy scTaxonomyRelation) {
\t \t this.scTaxonomyRelation = scTaxonomyRelation;
\t }
\t public Blueprint getBlueprintRelation() {
\t \t return blueprintRelation;
\t }
\t public void setBlueprintRelation(Blueprint blueprintRelation) {
\t \t this.blueprintRelation = blueprintRelation;
\t }
}
/**
*
*/
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> {
\t @Autowired
\t private CatalogueBlueprintService catalogueBlueprintService;
\t
\t @Autowired
\t private ScTaxonomyService scTaxonomyService;
\t
\t @Autowired
\t private BlueprintService blueprintService;
\t //create scTaxonomy relation
\t \t @RequestMapping(value = "/createScTaxonomyRelation", method = RequestMethod.POST)
\t \t public @ResponseBody BlueprintMessage relationTest(
\t \t \t \t @FormDataParam("ScTaxonomyId") String ScTaxonomyId,
\t \t \t \t @FormDataParam("blueprintId") String blueprintId,
\t \t \t \t @FormDataParam("catalogueBlueprintId") String catalogueBlueprintId, \t \t
\t \t \t \t @FormDataParam("onIaas") String onIaas,
\t \t \t \t @FormDataParam("script") String script,
\t \t \t \t @FormDataParam("step") String step, \t \t \t
\t \t \t \t @FormDataParam("x_axis") String x_axis,
\t \t \t \t @FormDataParam("y_axis") String y_axis,
\t \t \t \t final HttpServletResponse response) {
\t \t \t
\t \t \t ResponseStatus status = null;
\t \t \t Long blueptId = Long.parseLong(blueprintId);
\t \t \t Long taxonomyId = Long.parseLong(ScTaxonomyId); \t
\t \t \t List<CatalogueBlueprint> catalogueBPList = new ArrayList<CatalogueBlueprint>();
\t \t \t CatalogueBlueprint catalogueBP=new CatalogueBlueprint();
\t \t \t Blueprint blueprint=null; \t \t
\t \t \t ScTaxonomy taxonomy = null;
\t \t \t try {
\t \t \t \t
\t \t \t \t Long catalogueID=Long.parseLong(catalogueBlueprintId);
\t \t \t \t taxonomy = scTaxonomyService.find(taxonomyId);
\t \t \t \t \t \t \t \t \t
\t \t \t \t blueprint=blueprintService.find(blueptId);
\t \t \t \t
\t \t \t \t catalogueBP.setBlueprintRelation(blueprint);
\t \t \t \t catalogueBP.setScTaxonomyRelation(taxonomy);
\t \t \t \t
\t \t \t \t catalogueBP.setOnIaas(onIaas);
\t \t \t \t catalogueBP.setCatalogueBlueprintId(catalogueID);
\t \t \t \t catalogueBP.setScript(script); \t
\t \t \t \t catalogueBP.setStep(step); \t \t \t
\t \t \t \t catalogueBP.setX_axis(x_axis);
\t \t \t \t catalogueBP.setY_axis(y_axis);
\t \t \t \t catalogueBP.setIsDeleted("0"); \t \t
\t \t \t \t
\t \t \t \t catalogueBPList.add(catalogueBP); \t \t \t \t \t
\t \t \t \t \t \t
\t \t \t \t blueprint.addRelation(taxonomy, catalogueBP);
\t \t \t \t
\t \t \t \t super.create(blueprint);
\t \t \t \t //super.update(blueptId, blueprint);
\t \t \t
\t \t \t \t status = new ResponseStatus(ResponseStatusCode.STATUS_OK, "SUCCESS");
\t \t \t } catch (Exception e) {
\t \t \t \t e.printStackTrace();
\t \t \t }
\t \t \t return new BlueprintMessage(status, blueprint);
\t \t }
\t @Override
\t public MainService<Blueprint> getService() {
\t \t return blueprintService;
\t }
\t
}
這是很多代碼來消化。你可以請只發布相關secionts – e4c5
我怎麼能使用RelationshipEntity的neo4j.ogm春季啓動應用程序。 使用StartNode和EndNode – Karthikeyan
我假設你已經設法升級到4.0.0.RC2?先前版本中的關係實體存在問題。 – Luanne