Announcement Announcement Module
Collapse
No announcement yet.
NodeBacked.equals("some string here") throws Exception - bug? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NodeBacked.equals("some string here") throws Exception - bug?

    Hi,

    Today I've noted something which looks like a bug.

    When attempting .equals() on instance of @NodeEntity annotated class against instance of some non-@NodeEntity annotated class an exception is thrown. In my opinion it should just return false with no exceptions.

    For example:

    Code:
    @NodeEntity
    public class Person
    {
    ...
    }
    
    Person person = ....;// some loading from the Graph database
    person.equals("some string here"); //throws the exception
    Code:
    Exception in thread "main" org.springframework.data.neo4j.mapping.InvalidEntityTypeException: Type class java.lang.String is neither a @NodeEntity nor a @RelationshipEntity
    	at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.createPersistentEntity(Neo4jMappingContext.java:56)
    	at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.createPersistentEntity(Neo4jMappingContext.java:46)
    	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:271)
    	at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:61)
    	at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:46)
    	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:183)
    	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:158)
    	at org.springframework.data.neo4j.support.mapping.EntityStateHandler.getId(EntityStateHandler.java:82)
    	at org.springframework.data.neo4j.support.mapping.EntityStateHandler.getPersistentState(EntityStateHandler.java:99)
    	at org.springframework.data.neo4j.support.mapping.EntityStateHandler.equals(EntityStateHandler.java:260)
    	at org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking.ajc$interMethod$org_springframework_data_neo4j_aspects_support_node_Neo4jNodeBacking$org_springframework_data_neo4j_aspects_core_NodeBacked$equals(Neo4jNodeBacking.aj:235)
    ....

  • #2
    Hi,

    I found a way to workaround this issue by overriding the equals() and filtering out any non-NodeBacked objects:


    @Override
    public boolean equals(Object obj)
    {
    if (obj==null) return false;
    if (!(obj instanceof NodeBacked)) return false;

    return super.equals(obj);
    }

    Comment


    • #3
      hsherlock,

      I agree we should not throw exceptions.

      Can I ask you to create a ticket on https://jira.springsource.org/browse/DATAGRAPH so we can track this?

      Thanks,

      Lasse

      Comment


      • #4
        Hi Lasse,

        Created the issue: https://jira.springsource.org/browse/DATAGRAPH-279

        Cheers,

        Comment

        Working...
        X