I'm running into a problem with neo4j OGM library, I've followed the instruction on the library docs page to implement an abstract parent entity to contain all the shared fields and functionality of my entities. When I then inherit this class with a concrete one and try to perform session.save
, i get this error message MappingException: No identity field found for class: models.nodes.User
. I then tried to pull the id field down from the parent class to the child concrete class and the save operation succeeded - but, the other fields of the parent class were not persisted into the DB. My conclusion was that the OGM ignores the parent fields for some reason.
Here is my parent abstract 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;
}
}
And here is my concrete 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;
}
}
I've tried to both place the parent class inside the mapped package and out. <<-- EDIT: This was actually the problem, the parent class was not mapped by the OGM
Am I missing some required annotation? Is my parent class not mapped correctly? I'm using Play Framework 2.4 with Neo4j OGM version 1.1.4 from Maven using SBT builder.
Thanks.