java Neo4j OGM字段未继承
我遇到了neo4j OGM库的问题,我按照库docs page上的说明实现了一个抽象父实体,以包含实体的所有共享字段和功能。然后,当我用一个具体的类继承这个类并尝试执行session.save
时,我得到这个错误消息MappingException: No identity field found for class: models.nodes.User
。然后,我尝试将id字段从父类向下拉到子具体类,保存操作成功-但是,父类的其他字段没有持久化到DB中。我的结论是OGM出于某种原因忽略了父字段
这是我的父抽象类:
abstract public class MorpheusEntity {
// Fields
/**
* The ID of the entity
*/
@JsonProperty("id")
@GraphId
public Long id;
/**
* The date of first creation of the entity
*/
@DateString
private Date created;
/**
* The date of the last modification of the entity
*/
@DateString
private Date modified;
// Constructors
public MorpheusEntity() {
this.created = new Date();
this.modified = new Date();
}
// Methods
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || id == null || getClass() != o.getClass()) return false;
MorpheusEntity entity = (MorpheusEntity) o;
if (!id.equals(entity.id)) return false;
return true;
}
@Override
public int hashCode() {
return (id == null) ? -1 : id.hashCode();
}
// Getters / Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
}
这是我的具体儿童课程:
@NodeEntity
public class User extends MorpheusEntity {
// Fields
/**
* Facebook ID of the user
*/
private String facebookId;
/**
* First name of the user
*/
private String firstName;
/**
* Last name of the user
*/
private String lastName;
/**
* A URL address of the user avatar image
*/
private String avatarURL;
/**
* A set of friends of the user
*/
@Relationship(type = RelationshipNames.USER_FRIENDS, direction = Relationship.UNDIRECTED)
private Set<User> friends;
/**
* A set of user connected devices
*/
@Relationship(type = RelationshipNames.USER_DEVICES, direction = Relationship.OUTGOING)
private Set<Device> devices;
// Constructors
// Methods
// Getters / Setters
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAvatarURL() {
return avatarURL;
}
public void setAvatarURL(String avatarURL) {
this.avatarURL = avatarURL;
}
public Set<User> getFriends() {
return friends;
}
public void setFriends(Set<User> friends) {
this.friends = friends;
}
public Set<Device> getDevices() {
return devices;
}
public void setDevices(Set<Device> devices) {
this.devices = devices;
}
}
我已经尝试将父类放在映射包的内部和外部<<;——编辑:这实际上就是问题所在,OGM没有映射父类
我是否缺少一些必需的注释?我的父类映射不正确吗? 我正在使用PlayFramework2.4和来自Maven的Neo4j OGM version 1.1.4并使用SBT生成器
谢谢
# 1 楼答案
请检查在创建SessionFactory时是否正在注册抽象类包
# 2 楼答案
@NodeEntity
应该位于父类,并且它将被继承到子类参见文档中的Entity Type Representation部分