I'm trying to understand how to correctly use primary indexes in SDN 4.
From the org.neo4j.ogm.annotation.Index javadoc:
Only one index per class hierarchy may be marked as primary.
Does it mean that if I have a following entity hierarchy:
B extends A
C extends A
I can't add into the both entities B and C the following index definition :
#Index(unique = true, primary = true)
private Long id;
This primary index can be only added to A or to B or to C entity ?
Or if I can add the primary index into the both of them ( B and C), can B.id and C.id hold the same value.. for example 1
Only one index per class hierarchy may be marked as primary.
This means you can have only 1 primary index in a class, or any of its super classes.
E.g. if you have following hierarchy:
class A
class B extends A
class C extends B
you can have only 1 index, in either A, B or C.
In your situation you can have either index in A, or B (or B and C).
The difference is
if the index is in A, you won't be able to create B and C with same id - constraint on A label will be created
if the index is in B and C you can create B and C with same id, because it will be 2 separate constraints on 2 separate labels.
Related
How do I create a transitive relationship which maps back to the same initial label.
I am trying to map data from tables that go something like this :-
A -> B -> C -> A
B has the index column from A, and C has the index column from B and A (multiple). It is a kind of transitive relationship, wherein I need to map a specific row in A back to different rows in A. How do I go about doing this?
This is to be done on the labels for the whole data set, and not to be filtered for any given id. The labels are already existing in the db.
If you already have relations from A->B and B->C, then it can be simply achieved as follows, assuming the relationship type to be X:
MATCH (a:A)-[:X]->(:B)-[:X]->(c:C)
MERGE (c)-[:X]->(a)
This will create a relationship between every C and A, when they are linked via B
i want to map 2 different Ontologies A and B. But the classes i want to map have a different amount of object properties.Lets say A equals b. A is father and B is mother. class A:(gender, age, eyecolour, brother) class B:(age, gender, haircolour, sport)
the Union of A and B say C got:(gender, age, eyecolour, haircolour, sport) right? Is there any create statement in owL? or do i need to make the equvivalent to statement for the object properties. Is there any statement lets say if A got 2 brothers, create the object property x in B.
OWL classes aren't classes in the object-oriented programming sense, properties don't "belong" to classes in the sense that methods belong to classes (in many OO programming languages). When you say that the domain of a property P is the class C, it means that whenever you have an assertion
P(x,y)
you can infer that
x is a C
If you assert that the
P domain A
Q domain A
R domain B
S domain B
T domain B
and then assert that
C equivalentClass (A union B)
then you'll be able to infer that
P domain C
Q domain C
R domain C
S domain C
T domain C
Since, e.g.,
P(x,y)
implies
x is an A
which in turn implies that
x is a (A union B)
which implies that
x is a C
So C is a domain of P. I think that's what you're meaning when you say that "the class C has property P."
NB: I am using NHibernate 2.1 (for legacy code support)
If I have three entities:
A related to B
C related to B
That is, having the following properties:
Entity A
A
- id
- B
Entity B
B
- id
Entity C
C
- id
- B
How do I do it using a non-theta-style join?
If I try something like this
from A a
inner join a.B b
inner join C.b cB
where
a.B_id = b.id and
cB.id = b.id
I get the exception: Path expected for join!
Is a theta join the only way I can get it to work or am I missing something?
If I have no direct association from A to C why can I not associate through another entity? Or does this not work?
I need to find common node between two nodes. For example find B from A -> B -> C
A = node 1
B = node 2
C = node 3
A, B and C have common property (user_id, fullname) and relation property is KNOWS. node index is user_id.
Node related to:
A [:KNOWS] B and B [:KNOWS] C
I have A and C node id. I want find B node id. How can I do this using Cypher or neo4jphp?
Would really prefer to see something that you had written yourself, but I suppose sometimes that's just too much effort...
START a=node(1)
MATCH (a)-[:KNOWS]->(b)-[:KNOWS]->(c)
WHERE a.user_id = ... (Explanation on what exactly should be done here was lacking)
RETURN b
Seems simple, but having an issue:
model A
belong_to :B
model B
has_many :A
database tables:
table A:
id,...,b_id
table B:
id,...
When trying to create a new A, I set (an existing) B by doing:
a.b = B
I get an error saying "b can't be blank"
Instead of doing a.b = B, do a.b_id = B.id.
Think about how your collection and parent-child relationships work. You can -as suggested- add the ID of the relevant B to your A, but you may alternatively want to say B.a[] = a which would add "a" to your the "a" collection of your object "B". That way the relationship is set up in a more intuitive way, oriented towards the parent object rather than the child.
You should also be able to do newA = B.as.build ('as' being the plural of a).
Of course your examples of 'A, a, B and b` are very confusing! In the future use 'customer' & 'order' or 'blog' & 'post' or anything but cryptic letters with no meaning.