I created a simple SDN project to retrieve existing nodes from my database. In the repository, I defined a custom query using @Query annotation which is something like
@Query("MATCH (EMP:EMPLOYEE) WHERE EMP.empName={0} return EMP")
public Employee findByName(String empName);
@RelationshipEntity(type = "HAS_ADDRESS")
class AddressRelationShip
{
@GraphId
Long id;
@StartNode
Employee employee = null;
@EndNode
Address address = null;
public AddressRelationShip(Employee employee, Address address)
{
this.employee = employee;
this.address = address;
}
}
@NodeEntity
@TypeAlias("EMPLOYEE")
public class Employee
{
@GraphId
Long id;
String empName = null;
@RelatedTo(type = "HAS_ADDRESS", direction = Direction.OUTGOING)
@Fetch
Set<Address> addresses;
public void addressEmplployee(Address address)
{
if (addresses == null)
{
addresses = new HashSet<Address>();
}
//AddressRelationShip addressRelationShip = new AddressRelationShip(this, address);
addresses.add(address);
}
public Set<Address> getAddresses()
{
return addresses;
}
public void setAddresses(Set<Address> addresses)
{
this.addresses = addresses;
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getEmpName()
{
return empName;
}
public void setEmpName(String empName)
{
this.empName = empName;
}
}
With this query, on execution I get the below error message:
No primary SDN label exists .. (i.e one starting with _)
I googled about the issue and tried to use the below query:
MATCH (EMP:EMPLOYEE:_EMPLOYEE) WHERE EMP.EmployeeId={0} return EMP
This query runs but it doesn't return any response.
One important thing here is that I haven't created the existing nodes using SDN(I googled and found that SDN adds some metadata e.g, _ to nodes/relationships).
However, if I created the (Employee)-[HAS_ADDRESS]->(ADDRESS) pattern data using SDN, below query works fine:
MATCH (EMP:EMPLOYEE) WHERE EMP.empName={0} return EMP
In this case, I found one other issue that it returned address data as well while I'm only returning Employee in the query. I'm able to obtain the addresses from the Employee entity object.
Any pointers on the above issues?
PS - Neo4j is running in standalone server mode.
Regards, Rahul