Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First level relationship object is not getting converted with OGM returns null. #309

Closed
akandach opened this issue Dec 20, 2016 · 10 comments · Fixed by #326
Closed

First level relationship object is not getting converted with OGM returns null. #309

akandach opened this issue Dec 20, 2016 · 10 comments · Fixed by #326

Comments

@akandach
Copy link

akandach commented Dec 20, 2016

Retrieval of the relationship working fine from the chyper query.
But the same does not return the object model from the ogm, gives always null. Both http driver and bolt drive are not working. Same code use to work with older versions.

MATCH result = (a)-[r:`HAS_CONNECTION`]-(b) 
  where a.clidUuid = 'ac50203e-4089-40af-9ee1-eb1387801172' 
     and b.clidUuid = '0e7ed0c8-fe75-43d5-b4a4-0b4c09a81b79'
  RETURN result

no logs after this

14:10:10.758 [http-nio-8088-exec-1] INFO  o.n.o.d.http.request.HttpRequest - Thread: 196, url: http://localhost:7474/db/data/transaction/197, request: {"statements":[{"statement":"MATCH result = (a)-[r:`HAS_CONNECTION`]-(b) where a.clidUuid = {`startProfileId`} and b.clidUuid = {`endProfileId`} RETURN result","parameters":{"startProfileId":"ac50203e-4089-40af-9ee1-eb1387801172","endProfileId":"0e7ed0c8-fe75-43d5-b4a4-0b4c09a81b79"},"resultDataContents":["graph"],"includeStats":false}]}

Neo4j version - 3.0.6
neo4j-ogm.version 2.1.1-SNAPSHOT
spring boot version : 1.5.0.BUILD-SNAPSHOT

@akandach akandach changed the title First level relationship object is not getting converted. First level relationship object is not getting converted with OGM returns null. Dec 20, 2016
@mangrish
Copy link
Contributor

@akandach: Please check out the information box in this section: http://docs.spring.io/spring-data/neo4j/docs/4.2.x/reference/html/#reference_programming_model_annotatedQueries

Custom queries do not support a custom depth. Additionally, @query does not support mapping a path to domain entities, as such, a path should not be returned from a Cypher query. Instead, return nodes and relationships to have them mapped to domain entities.

To fix this simply return a,r,n and remove the path from the MATCH statement.

@akandach
Copy link
Author

akandach commented Dec 20, 2016

still same issue:

MATCH (a)-[r:`HAS_CONNECTION`]-(b) where a.clidUuid = {`startProfileId`} and b.clidUuid = {`endProfileId`} RETURN a,r,b
@Query("MATCH (a)-[r:`HAS_CONNECTION`]-(b) where a.clidUuid = {`startProfileId`} and b.clidUuid = {`endProfileId`} RETURN a,r,b")
	ProfileToProfile loadProfileToProfile(@Param("startProfileId") String startProfileId,
			@Param("endProfileId") String endProfileId);

@akandach
Copy link
Author

akandach commented Dec 20, 2016

Getting this error:

16:53:38.935 [http-nio-8088-exec-10] INFO  o.n.o.d.bolt.request.BoltRequest - Request: MATCH (a)-[r:`HAS_CONNECTION`]-(b) where a.clidUuid = {`startProfileId`} and b.clidUuid = {`endProfileId`} RETURN r with params {startProfileId=b3622f04-c795-48ce-b691-e346826149ac, endProfileId=0e7ed0c8-fe75-43d5-b4a4-0b4c09a81b79}
16:53:38.937 [http-nio-8088-exec-10] DEBUG o.n.ogm.context.GraphEntityMapper - Relationship (7)-[HAS_CONNECTION]->(16) cannot be hydrated because one or more required node types are not mapped to entity classes

Same code use to work before upgrade to 2.1.1 ogm and 1.5.0 spring boot.

Added object model

import java.util.List;

import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.Property;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;

import com.clidentity.enums.ConnectionType;
import com.clidentity.enums.ReadWrite;
import com.clidentity.personal.profile.model.Profile;

/**
 * @author: K Anil
 */
@RelationshipEntity(type = RelationshipTypes.HAS_CONNECTION)
public class ProfileToProfile extends IdentifiableRelationship {

	@StartNode
	private Profile start;

	@EndNode
	private Profile end;

	@Property
	private ConnectionType connectionType;

	@Property
	private String startProfileId;

	@Property
	private String endProfileId;

	@Property
	private List<String> disconnectedProfileIds;

	@Property
	private List<String> fromAttributesPermissions;

	@Property
	private List<String> toAttributesPermissions;
	
	@Property
	private ReadWrite readWrite;
	
	protected ProfileToProfile() {
	}
	
	public ProfileToProfile(Profile start, Profile end) {
		super();
		setPrimaryKey(start.getClidUuid() + "_" + end.getClidUuid());
		this.start = start;
		this.end = end;
		
		this.setStartProfileId(start.getClidUuid());
		this.setEndProfileId(end.getClidUuid());
	}

	public String getStartProfileId() {
		return startProfileId;
	}

	public void setStartProfileId(String startProfileId) {
		this.startProfileId = startProfileId;
	}

	public String getEndProfileId() {
		return endProfileId;
	}

	public void setEndProfileId(String endProfileId) {
		this.endProfileId = endProfileId;
	}

	public Profile getStart() {
		return start;
	}

	public Profile getEnd() {
		return end;
	}

	public void setStart(Profile start) {
		this.start = start;
	}

	public void setEnd(Profile end) {
		this.end = end;
	}

	public ConnectionType getConnectionType() {
		return connectionType;
	}

	public void setConnectionType(ConnectionType connectionType) {
		this.connectionType = connectionType;
	}

	public List<String> getFromAttributesPermissions() {
		return fromAttributesPermissions;
	}

	public void setFromAttributesPermissions(List<String> fromAttributesPermissions) {
		this.fromAttributesPermissions = fromAttributesPermissions;
	}

	public List<String> getToAttributesPermissions() {
		return toAttributesPermissions;
	}

	public void setToAttributesPermissions(List<String> toAttributesPermissions) {
		this.toAttributesPermissions = toAttributesPermissions;
	}

	public List<String> getDisconnectedProfileIds() {
		return disconnectedProfileIds;
	}

	public void setDisconnectedProfileIds(List<String> disconnectedProfileIds) {
		this.disconnectedProfileIds = disconnectedProfileIds;
	}

	public ReadWrite getReadWrite() {
		return readWrite;
	}

	public void setReadWrite(ReadWrite readWrite) {
		this.readWrite = readWrite;
	}
}

====================

@NodeEntity
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({ @Type(value = DepartmentProfile.class), @Type(value = LocationProfile.class),
		@Type(value = PersonalContactInfoProfile.class), @Type(value = CustomProfile.class),
		@Type(value = EventProfile.class)})
public abstract class Profile extends IdentifiableEntity {

	@Index
	private String profileName;

	private String picture;

	private ProfileType profileType;

	private boolean isPublic;

	// private boolean isVisible;

	private boolean isSearchable;

	@Transient
	private String name;

	@Transient
	private Map<String, Object> customProperties = new HashMap<String, Object>();

	protected Profile() {

	}

	public Profile(String profileName, ProfileType profileType) {
		super();
		//setPrimaryKey(name + "_" + profileName);
		setProfileName(profileName);
		setProfileType(profileType);
	}

	public Profile(String profileName, ProfileType profileType, boolean isPublic) {
		super();
		//setPrimaryKey(name + "_" + profileName);
		setProfileName(profileName);
		setProfileType(profileType);
		setPublic(isPublic);
	}

	public String getProfileName() {
		return profileName;
	}

	public void setProfileName(String profileName) {
		this.profileName = profileName;
	}

	public ProfileType getProfileType() {
		return profileType;
	}

	public void setProfileType(ProfileType profileType) {
		this.profileType = profileType;
	}

	public boolean isPublic() {
		return isPublic;
	}

	public void setPublic(boolean isPublic) {
		this.isPublic = isPublic;
	}

	public boolean isSearchable() {
		return isSearchable;
	}

	public void setSearchable(boolean isSearchable) {
		this.isSearchable = isSearchable;
	}

	/*public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}*/

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public Map<String, Object> getCustomProperties() {
		return customProperties;
	}

	public void setCustomProperties(Map<String, Object> customProperties) {
		this.customProperties = customProperties;
	}

	public String getName() {
		return name;
	}

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

@akandach
Copy link
Author

akandach commented Dec 20, 2016

Now i am seeing this logs but still returns null

19:15:54.546 [http-nio-8088-exec-4] DEBUG o.s.d.n.t.Neo4jTransactionManager - Beginning Transaction [org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction@104540d6] on Session [org.neo4j.ogm.session.Neo4jSession@68a1607]
19:15:57.741 [http-nio-8088-exec-4] INFO  o.n.o.d.bolt.request.BoltRequest - Request: MATCH result = (a)-[r:`HAS_CONNECTION`]-(b) where a.clidUuid = {`startProfileId`} and b.clidUuid = {`endProfileId`} RETURN result with params {startProfileId=b3622f04-c795-48ce-b691-e346826149ac, endProfileId=0e7ed0c8-fe75-43d5-b4a4-0b4c09a81b79}
19:15:57.766 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - looking for concrete class to resolve label: IdentifiableEntity
19:15:57.767 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - label is on an abstract class. Looking for a single concrete subclass...
19:15:57.767 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - More than one class subclasses com.clidentity.model.IdentifiableEntity
19:15:57.768 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - no implementing class or concrete subclass found!
19:15:57.768 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - looking for concrete class to resolve label: PublicProfile
19:15:57.769 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - concrete class found: com.clidentity.personal.profile.model.PublicProfile. comparing with what's already been found previously...
19:15:57.769 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - PublicProfile resolving class: com.clidentity.personal.profile.model.PublicProfile
19:15:57.770 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - looking for concrete class to resolve label: Profile
19:15:57.770 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - label is on an abstract class. Looking for a single concrete subclass...
19:15:57.770 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - More than one class subclasses com.clidentity.personal.profile.model.Profile
19:15:57.770 [http-nio-8088-exec-4] DEBUG org.neo4j.ogm.MetaData - no implementing class or concrete subclass found!
19:15:57.790 [http-nio-8088-exec-4] DEBUG o.n.o.c.register.EntityRegister - Added object to node registry: 16, com.clidentity.personal.profile.model.PublicProfile@675c8d74
19:15:57.812 [http-nio-8088-exec-4] DEBUG o.n.o.c.register.EntityRegister - Added object to node registry: 7, com.clidentity.personal.profile.model.PublicProfile@6e7da9b4

@akandach
Copy link
Author

any update on this?

@akandach
Copy link
Author

why is this bug closed? Still there is an issue with OGM 2.1.1.
I reverted back OGM 2.1.0 for now it is working fine.

@mangrish
Copy link
Contributor

Hey Anil,

I will take a look at this when I can. I'm currently on holidays though so it might take a few days.

@mangrish mangrish reopened this Dec 22, 2016
@akandach
Copy link
Author

No issues @mangrish. I have reverted the version for now and everything is working fine. So, i will wait for the fix.

@mangrish
Copy link
Contributor

mangrish commented Jan 6, 2017

@akandach: We have a test here: https://github.com/spring-projects/spring-data-neo4j/blob/master/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/DerivedRelationshipEntityQueryIT.java

The test to search for is: shouldFindREFromCustomQuery().

This does something very similar to what you are doing and it passes.

Would you be able to provide a stand alone test to replicate this issue?

@nmervaillie
Copy link
Member

@akandach It's probably because the relationship to ProfileToProfile is not an attribute of your Profile entity.

Having to declare the relationships in your entities is problematic for you ?
If so, can you describe a bit more your use case ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants