Java Neo4j OGM与接口配合得好吗?

Java Neo4j OGM与接口配合得好吗?,java,neo4j,neo4j-ogm,Java,Neo4j,Neo4j Ogm,我开发了两组类——第一组只是类,而在第二组中,类派生自接口。这两组类都互相模仿。它们的存储库也类似。但是,存储库对于第一组类(节点和关系)运行良好。但是对于第二组类,存储库可以插入记录,但是findAll方法失败,并且不返回任何记录 下面是存储库中的第一组类- public abstract class Entity { @GraphId private Long id; public Long getId() { return id; }

我开发了两组类——第一组只是类,而在第二组中,类派生自接口。这两组类都互相模仿。它们的存储库也类似。但是,存储库对于第一组类(节点和关系)运行良好。但是对于第二组类,存储库可以插入记录,但是findAll方法失败,并且不返回任何记录

下面是存储库中的第一组类-

public abstract class Entity {
    @GraphId
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || id == null || getClass() != o.getClass()) return false;

        Entity entity = (Entity) o;
        if (!id.equals(entity.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return (id == null) ? -1 : id.hashCode();
    }
}

public abstract class GenericRepository<T> implements IGenericRepository<T> {
    private static final int DEPTH_LIST = 1;

    private static final int DEPTH_ENTITY = 2;

    private Session session;

    public GenericRepository(String url, String username, String password) {
        super();
        session = Neo4jSessionFactory.getInstance().getNeo4jSession(url, username, password);
    }

    public Iterable<T> findAll() {
        return session.loadAll(getEntityType(), DEPTH_LIST);
    }

    public T findOne(Long id) {
        return session.load(getEntityType(), id, DEPTH_ENTITY);
    }

    public void delete(T entity) {
        session.delete(session.load(getEntityType(), ((Entity) entity).getId()));
    }

    public T createOrUpdate(T entity) {
        session.save(entity, DEPTH_ENTITY);
        return findOne(((Entity) entity).getId());
    }

    public abstract Class<T> getEntityType();
}

@RelationshipEntity(type="MY_ROLE")
public class ARole extends Entity {
    @Property
    private String title;

    @StartNode
    private HomoSapiens start;

    @EndNode
    private HomoSapiens end;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public HomoSapiens getStart() {
        return start;
    }

    public void setStart(HomoSapiens start) {
        this.start = start;
    }

    public HomoSapiens getEnd() {
        return end;
    }

    public void setEnd(HomoSapiens end) {
        this.end = end;
    }

    public ARole() {}
    public ARole(String title) {
        this.title = title;
    }
}

@NodeEntity
 public class HomoSapiens extends Entity {
    private String name;

    @Relationship(type = "MY_ROLE", direction = Relationship.INCOMING)
    private ARole aRole;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ARole getaRole() {
        return aRole;
    }

    public void setaRole(ARole aRole) {
        this.aRole = aRole;
    }

    public HomoSapiens() {}
    public HomoSapiens(String name) {
        this.name = name;
    }
}

public class ARoleDao extends GenericRepository<ARole> implements IARoleDao {
    public ARoleDao(String url, String username, String password) {
        super(url, username, password);
    }

    @Override
    public Class<ARole> getEntityType() {
        return ARole.class;
    }
}
公共抽象类实体{
@格拉希德
私人长id;
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
@凌驾
公共布尔等于(对象o){
如果(this==o)返回true;
如果(o==null | | id==null | | getClass()!=o.getClass())返回false;
实体=(实体)o;
如果(!id.equals(entity.id))返回false;
返回true;
}
@凌驾
公共int hashCode(){
返回值(id==null)?-1:id.hashCode();
}
}
公共抽象类GenericRepository实现了IGenericRepository{
私有静态最终整数深度_列表=1;
私有静态最终整数深度_实体=2;
非公开会议;
公共GenericRepository(字符串url、字符串用户名、字符串密码){
超级();
session=Neo4jSessionFactory.getInstance().getNeo4jSession(url、用户名、密码);
}
公共可引用findAll(){
返回session.loadAll(getEntityType(),深度列表);
}
公共T findOne(长id){
返回session.load(getEntityType(),id,DEPTH\u ENTITY);
}
公共作废删除(T实体){
delete(session.load(getEntityType(),((Entity)Entity.getId());
}
公共T createOrUpdate(T实体){
session.save(实体、深度实体);
返回findOne(((Entity)Entity.getId());
}
公共抽象类getEntityType();
}
@RelationshipEntity(type=“我的角色”)
公共类ARole扩展实体{
@财产
私有字符串标题;
@StartNode
私人智人开始;
@端节点
私人智人目的;
公共字符串getTitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共智人getStart(){
返回启动;
}
公共void setStart(智人启动){
this.start=start;
}
公共智人{
返回端;
}
公共空间设置端(智人端){
this.end=end;
}
公共ARole(){}
公共ARole(字符串标题){
this.title=标题;
}
}
@节点性
公共类智人扩展实体{
私有字符串名称;
@关系(type=“MY_ROLE”,direction=Relationship.INCOMING)
私人住宅;
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共阿罗勒-赫塔罗勒(){
返回aRole;
}
公共空间塞塔罗勒(阿罗勒-阿罗勒){
this.aRole=aRole;
}
公共智人(){}
公共智人(字符串名称){
this.name=名称;
}
}
公共类ARoleDao扩展了GenericRepository(如果有帮助的话)。
谢谢

Manoj.

这应该在1.1.3中固定

在发布之前,请使用
1.1.3-SNAPSHOT
尝试您的代码示例

你需要包括

 <repository>
        <id>neo4j-snapshots</id>
        <url>http://m2.neo4j.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>

neo4j快照
http://m2.neo4j.org/content/repositories/snapshots
真的

异常说明了什么?很抱歉,我没有得到异常,但是在should\u find\u all测试中,返回的derivedARoles不是null,但是下一个assert语句Iterables.isEmpty失败(甚至计数为0)。我不明白,你得到了异常还是只有你的assert语句失败了?你是对的,我没有得到异常,但是断言失败了。我将修改这个问题。刚刚修改了原来的问题。谢谢Luane,快照版本非常好用。您知道1.1.3最终版本大概什么时候发布吗?
 <repository>
        <id>neo4j-snapshots</id>
        <url>http://m2.neo4j.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>