0
votes

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

1
I'm facing another issue with relationships now. My query return clause has one node, relationship, another node. I'm getting below error: org.neo4j.graphdb.NotFoundException: No such property, 'type'. It seems that I need to add additional relationship type in relationshiptype format. But I couldn't find a way to do that for existing data. Can anyone suggest how to add a new relationshiptype to existing relationship?Rahul

1 Answers

0
votes

I could resolve the above issues in following steps:

  1. No primary SDN label exists .. (i.e one starting with _) - In SDN 3.3.0, for existing nodes, SDN requires an extra label (in my case, _EMPLOYEE), so a data migration is required. In SDN 4.0, It seems that this is no longer needed but I haven't tried 4.0 yet.
  2. Returning address data as well while I'm only returning Employee in the query - Removing @Fetch on Set addresses in Employee resolved this, However, addresses nodeIds were still returned.

To run SDN 3.x.x with existing data, following data migration is required:

  1. Add additional NodeLabel(preceding the original label with _) to nodes, e.g, add _Employee label to all Employee nodes.
  2. Add __type__ property to nodes and relationships whose value will be fully qualified name for the appropriate domain/model classes, e.g, match (n:Employee) set n.__type__="org.neo4j.domain.Employee"

Cheers,

Rahul