Comments (13)
@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.
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.
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.
@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.
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.
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.
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.
Never mind, I think you addressed this in #85
from neo4j-ogm.
@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.
@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.
@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.
@luanne thank you again for the clarification - makes sense.
from neo4j-ogm.
@luanne perfect, thank you!
from neo4j-ogm.
Related Issues (20)
- OGM Session.load(entity, id, depth) result incorrect when entity have a field is same type with entity
- Bumping classgraph for v3.3.x and v3.2.x HOT 2
- How to extend a customized driver with ogm based on this repo? HOT 2
- Result not of expected size exception while finding by id when a connected node have the same type HOT 3
- Cannot use name of field converted with a `CompositeAttributeConverter` in converted map HOT 2
- Extension points in OGM Session to provide Transaction Manager HOT 5
- Updating neo4j-ogm from 3.1.2 to 3.2.39 giving org.neo4j.ogm.exception.core.NotFoundException error HOT 1
- Feature Request: Include node/relationship IDs in OptimisticLockingException HOT 2
- Neo4j OGM general question HOT 7
- @Formula annotation in nodes for calculable fields HOT 3
- Nullpointer when Neo.ClientNotification.Statement.CodeGenerationFailed HOT 5
- Direct Relationship Persistence Issue HOT 10
- OGM returns empty result if query results contains nodes and rels with same native id HOT 5
- Delete this repository HOT 2
- SDN OGM @Properties for Map of Collections HOT 4
- Neo4j Access to record went out of bounds of the page HOT 2
- Unit test for GH-952 now useless HOT 2
- Lots Of Deprecation Warnings about the Use of ID function HOT 4
- java.lang.UnsupportedOperationException: This method has been deprecated and should not have been called HOT 4
- How to use ImpersonatedUser in neo4j ogm session HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neo4j-ogm.