Neo4j OGM 字段未继承
Neo4j OGM fields not inherited
我 运行 遇到了 neo4j OGM library, I've followed the instruction on the library docs page 实现抽象 parent 实体以包含我的实体的所有共享字段和功能的问题。然后,当我用一个具体的继承此 class 并尝试执行 session.save
时,我收到此错误消息 MappingException: No identity field found for class: models.nodes.User
。然后我尝试将 id 字段从 parent class 下拉到 child 具体 class 并且保存操作成功 - 但是 [=39 的其他字段=] class 没有保存到数据库中。我的结论是 OGM 出于某种原因忽略了 parent 字段。
这是我的 parent 摘要 class:
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;
}
}
这是我的具体 child class:
@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;
}
}
我试过将 parent class 放在映射包内和外。 <<-- 编辑:这实际上是问题所在,parent class 未被 OGM
映射
我是否遗漏了一些必需的注释?我的 parent class 是不是映射不正确?
我正在使用 Play Framework 2.4 和 Neo4j OGM version 1.1.4 来自 Maven 使用 SBT 构建器。
谢谢。
@NodeEntity
应该在父级 class 并且它将继承给子级 class。
请参阅文档中的 Entity Type Representation 部分
请检查创建 SessionFactory 时是否正在注册您的抽象 class 包。
我 运行 遇到了 neo4j OGM library, I've followed the instruction on the library docs page 实现抽象 parent 实体以包含我的实体的所有共享字段和功能的问题。然后,当我用一个具体的继承此 class 并尝试执行 session.save
时,我收到此错误消息 MappingException: No identity field found for class: models.nodes.User
。然后我尝试将 id 字段从 parent class 下拉到 child 具体 class 并且保存操作成功 - 但是 [=39 的其他字段=] class 没有保存到数据库中。我的结论是 OGM 出于某种原因忽略了 parent 字段。
这是我的 parent 摘要 class:
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;
}
}
这是我的具体 child class:
@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;
}
}
我试过将 parent class 放在映射包内和外。 <<-- 编辑:这实际上是问题所在,parent class 未被 OGM
映射我是否遗漏了一些必需的注释?我的 parent class 是不是映射不正确? 我正在使用 Play Framework 2.4 和 Neo4j OGM version 1.1.4 来自 Maven 使用 SBT 构建器。
谢谢。
@NodeEntity
应该在父级 class 并且它将继承给子级 class。
请参阅文档中的 Entity Type Representation 部分
请检查创建 SessionFactory 时是否正在注册您的抽象 class 包。