gpt4 book ai didi

java - Neo4j OGM 字段不继承

转载 作者:行者123 更新时间:2023-12-02 04:00:27 28 4
gpt4 key购买 nike

我遇到了 neo4j OGM 的问题图书馆,我已按照图书馆 docs page 上的说明进行操作实现一个抽象父实体以包含我的实体的所有共享字段和功能。然后,当我用具体的类继承此类并尝试执行 session.save 时,我收到此错误消息 MappingException: No Identity field found for class: models.nodes.User。然后,我尝试将 id 字段从父类拉到子具体类,并且保存操作成功 - 但是,父类的其他字段没有持久化到数据库中。我的结论是 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 未映射父类

我是否缺少一些必需的注释?我的父类映射不正确吗?我正在使用 Play Framework 2.4 和 Neo4j OGM version 1.1.4使用 SBT 构建器从 Maven 中获取。

谢谢。

最佳答案

请检查您的抽象类包在创建 SessionFactory 时是否已注册。

关于java - Neo4j OGM 字段不继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34969209/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com