org.neo4j.ogm.exception.MappingException: Error mapping GraphModel to instance of ***.ProjectGraph解析

虾米哥 阅读:238 2021-03-31 14:11:46 评论:0

实例化知识图谱对象ProjectGraph.java 提示如下截图错误信息:

 Exception in thread "main" org.neo4j.ogm.exception.MappingException: Error mapping GraphModel to instance of <package>.ProjectGraph 
    at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:145) 
    at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:117) 
    at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:81) 
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:111) 
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:82) 
    at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:323) 
 
Caused by: org.neo4j.ogm.exception.MappingException: Unable to instantiate class <package>.ProjectGraph 
    at org.neo4j.ogm.annotations.EntityFactory.instantiate(EntityFactory.java:137) 
    at org.neo4j.ogm.annotations.EntityFactory.instantiateObjectFromTaxa(EntityFactory.java:110) 
    at org.neo4j.ogm.annotations.EntityFactory.newObject(EntityFactory.java:61) 
    at org.neo4j.ogm.context.GraphEntityMapper.mapNodes(GraphEntityMapper.java:156) 
    at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:142) 
    ... 7 more 
Caused by: java.lang.NoSuchMethodException: <package>.ProjectGraph.<init>() 
    at java.lang.Class.getConstructor0(Class.java:3082) 
    at java.lang.Class.getDeclaredConstructor(Class.java:2178) 
    at org.neo4j.ogm.annotations.EntityFactory.instantiate(EntityFactory.java:133) 
    ... 11 more

造成的原因:ProjectGraph.java 需要没有任何属性的构造函数,补全ProjectGraph 没有任何属性的构造函数。

ProjectGraph.java 错误代码:

 
import java.util.List; 
 
import org.neo4j.ogm.annotation.GraphId; 
import org.neo4j.ogm.annotation.NodeEntity; 
import org.neo4j.ogm.annotation.Relationship; 
 
/** 
 * 单位工程图谱对象 
 *  
 * 
 */ 
@NodeEntity 
@SuppressWarnings("serial") 
public class ProjectGraph implements java.io.Serializable{ 
	@GraphId 
	private Long id; 
	private String name; 
	private String sid; 
	 
	@Relationship(type = "IndividualLicenseRelation") 
	private List<LicenseGraph> licenses; 
	 
	@Relationship(type = "IndividualResponRelation") 
	private List<ResponGraph> respons; 
	 
	@Relationship(type = "IndividualUnitRelation") 
	private List<UnitGraph> units; 
	 
	//set 和 get 方法 
	public Long getId() { 
		return id; 
	} 
	public void setId(Long id) { 
		this.id = id; 
	} 
	public String getName() { 
		return name; 
	} 
	public void setName(String name) { 
		this.name = name; 
	} 
	public String getSid() { 
		return sid; 
	} 
	public void setSid(String sid) { 
		this.sid = sid; 
	} 
 
	public List<LicenseGraph> getLicenses() { 
		return licenses; 
	} 
	public void setLicenses(List<LicenseGraph> licenses) { 
		this.licenses = licenses; 
	} 
	public List<ResponGraph> getRespons() { 
		return respons; 
	} 
	public void setRespons(List<ResponGraph> respons) { 
		this.respons = respons; 
	} 
	public List<UnitGraph> getUnits() { 
		return units; 
	} 
	public void setUnits(List<UnitGraph> units) { 
		this.units = units; 
	} 
	 
	public ProjectGraph(String name, String sid) { 
		this.name = name; 
		this.sid = sid; 
	} 
	 
} 

ProjectGraph.java 修正后的代码:

 
import java.util.List; 
 
import org.neo4j.ogm.annotation.GraphId; 
import org.neo4j.ogm.annotation.NodeEntity; 
import org.neo4j.ogm.annotation.Relationship; 
 
/** 
 * 单位工程图谱对象 
 *  
 * 
 */ 
@NodeEntity 
@SuppressWarnings("serial") 
public class ProjectGraph implements java.io.Serializable{ 
	@GraphId 
	private Long id; 
	private String name; 
	private String sid; 
	 
	@Relationship(type = "IndividualLicenseRelation") 
	private List<LicenseGraph> licenses; 
	 
	@Relationship(type = "IndividualResponRelation") 
	private List<ResponGraph> respons; 
	 
	@Relationship(type = "IndividualUnitRelation") 
	private List<UnitGraph> units; 
	 
	//set 和 get 方法 
	public Long getId() { 
		return id; 
	} 
	public void setId(Long id) { 
		this.id = id; 
	} 
	public String getName() { 
		return name; 
	} 
	public void setName(String name) { 
		this.name = name; 
	} 
	public String getSid() { 
		return sid; 
	} 
	public void setSid(String sid) { 
		this.sid = sid; 
	} 
 
	public List<LicenseGraph> getLicenses() { 
		return licenses; 
	} 
	public void setLicenses(List<LicenseGraph> licenses) { 
		this.licenses = licenses; 
	} 
	public List<ResponGraph> getRespons() { 
		return respons; 
	} 
	public void setRespons(List<ResponGraph> respons) { 
		this.respons = respons; 
	} 
	public List<UnitGraph> getUnits() { 
		return units; 
	} 
	public void setUnits(List<UnitGraph> units) { 
		this.units = units; 
	} 
	// 构造函数 
	public ProjectGraph() { 
		super(); 
	} 
 
	public ProjectGraph(String name, String sid) { 
		this.name = name; 
		this.sid = sid; 
	} 
	 
} 

 

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们