Giter Club home page Giter Club logo

Comments (13)

luanne avatar luanne commented on June 14, 2024 1

@charliebonza there are two reasons your test was failing. The first is that the annotations need to be explicit. INCOMING relationships must have annotations on methods as well if present.

In cases where the mapping may be ambiguous like the one in this issue as well as your test case, recommendation is that a) the objects be navigable in both directions and b) the @relationship annotations are explicit. This means if you have methods, they must be annotated.

The User should now look like:


    @Relationship(type = "OWNER", direction = Relationship.INCOMING)
    private Set<OwnedLicensedEntity> owned;

    @Relationship(type = "LICENSEE", direction = Relationship.INCOMING)
    private Set<OwnedLicensedEntity> licensed;

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    @Relationship(type = "LICENSEE", direction = Relationship.INCOMING)
    public Set<OwnedLicensedEntity> getLicensed() {
        return licensed;
    }

    @Relationship(type = "LICENSEE", direction = Relationship.INCOMING)
    public void setLicensed(Set<OwnedLicensedEntity> licensed) {
        this.licensed = licensed;
    }

    @Relationship(type = "OWNER", direction = Relationship.INCOMING)
    public Set<OwnedLicensedEntity> getOwned() {
        return owned;
    }

    @Relationship(type = "OWNER", direction = Relationship.INCOMING)
    public void setOwned(Set<OwnedLicensedEntity> owned) {
        this.owned = owned;
    }

and OwnedLicensedEntity like

@Relationship(type = "OWNER", direction = Relationship.OUTGOING)
    private User owner;

    @Relationship(type = "LICENSEE", direction = Relationship.OUTGOING)
    private Set<User> licensees;

    @Relationship(type = "LICENSEE", direction = Relationship.OUTGOING)
    public Set<User> getLicensees() {
        return licensees;
    }

    @Relationship(type = "LICENSEE", direction = Relationship.OUTGOING)
    public void setLicensees(Set<User> licensees) {
        this.licensees = licensees;
    }

    @Relationship(type = "OWNER", direction = Relationship.OUTGOING)
    public User getOwner() {
        return owner;
    }

    @Relationship(type = "OWNER", direction = Relationship.OUTGOING)
    public void setOwner(User owner) {
        this.owner = owner;
    }

The second issue contributing to this behaviour was issue #85 which is now fixed and available in 1.1.4-SNAPSHOT

from neo4j-ogm.

luanne avatar luanne commented on June 14, 2024

Scrub notes:

When mapping (:MyContainer:MyResource:MyEntity)-[:ADDITIONAL_CHILD]->(MyResource:MyEntity), tryMappingAsSingleton (outgoing) writes to MyContainer.additionalChild. But tryMappingAsSingleton (incoming) cannot find anything to write to, so it adds the edge to mapOneToMany. Here, a strict match by annotation type and direction cannot be found, so the loose criteria it matches against is the node entity type, MyResource. Should really remember that it's already successfully mapped this edge as a scalar in the OUTGOING direction and only attempt an INCOMING manyToOne mapping.

from neo4j-ogm.

charliebonza avatar charliebonza commented on June 14, 2024

Any update on this bug please? This has been a blocker for me in a couple of areas for a while now. Is there any viable workaround? Thank you.

from neo4j-ogm.

vince-bickers avatar vince-bickers commented on June 14, 2024

@charliebonza please could you confirm whether this problem still exists in the latest snapshot build? #78 has been fixed and your issue #38 is believed fixed as well. Thanks

from neo4j-ogm.

charliebonza avatar charliebonza commented on June 14, 2024

Hello @vince-bickers, thank you for the reply and sorry for the delay coming back to you. I'm afraid that I still have a failing test case with the latest 1.1.4-SNAPSHOT version of the neo4j-ogm library. I've put the test into a GitHub repo: https://github.com/charliebonza/OgmTest with a README and wiki page. Hopefully it makes sense. Thank you again.

from neo4j-ogm.

luanne avatar luanne commented on June 14, 2024

In cases where the mapping may be ambiguous like the one in this issue, the recommendation is that
a) the objects be navigable in both directions and
b) the @relationship annotations are explicit. This means if the entity has setter methods, they must be annotated

from neo4j-ogm.

tarehart avatar tarehart commented on June 14, 2024

I'm content to make my objects navigable in both directions, but I'm very concerned that getRelationalWriter can silently fail over into INFERRED_MODE. This is a situation where it's critical to fail fast and loud because this behavior easily has the potential to hose a database. I would prefer to force strict mode all the time (never ignoring edge types) and get exceptions if/when they're warranted.

Even knowing the solution, I feel like it's just a matter of time until I get bitten by this again. Would you consider providing some kind of configuration option?

A link to my jira for extra context: https://jira.spring.io/browse/DATAGRAPH-788

from neo4j-ogm.

tarehart avatar tarehart commented on June 14, 2024

Never mind, I think you addressed this in #85

from neo4j-ogm.

luanne avatar luanne commented on June 14, 2024

@tarehart yes, ignoring the relationship type that's been specified via an annotation should never have happened whether strict or inferred mode. #85 fixes that.

from neo4j-ogm.

charliebonza avatar charliebonza commented on June 14, 2024

@luanne thank you very much for your detailed reply. I'll implement those changes. As you could tell I've only be annotating fields so far not methods!

from neo4j-ogm.

luanne avatar luanne commented on June 14, 2024

@charliebonza note that it is only for this specific case that annotations are required on both fields and methods (if they exist). For all others, the OGM will attempt to use annotated methods first, followed by fields, followed by methods/fields not annotated but with names derived from relationship types and matching params.
INCOMING relationships must have annotations on both fields and methods if they exist, in every case.

from neo4j-ogm.

charliebonza avatar charliebonza commented on June 14, 2024

@luanne thank you again for the clarification - makes sense.

from neo4j-ogm.

tarehart avatar tarehart commented on June 14, 2024

@luanne perfect, thank you!

from neo4j-ogm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.