Prabjot Singh
Prabjot Singh

Reputation: 4767

Spring Data Neo4j(Getting error "Cannot obtain single field value for field")

I am getting error:"Cannot obtain single field value for field 'creator'",so i am not getting it,why it is coming.actually,when i create unique relationship,when i am fetching,then it is coming.I am using SDN with neo4j embedded.so,please help me to resolve it

my domain class

@NodeEntity
class CrowdFunding extends BaseEntity{
    String fundingFor
    String title

@RelatedTo(type="HAS_USER")
    User creator
}

my repository

@Query("Match (n:CrowdFunding) WHERE id(n)={0} match (user:User) where id(user) in {1} WITH n,user create unique (n)-[:HAS_USER {is_owner:false,is_contact_person:true,is_wishlist_crowdFunding:false,is_blacklist_crowdFunding:false}]->(user)")
    saveCrowdFundingContacts(long id,List contacts)

My controller

CrowdFunding crowdFunding = findOne(id,CrowdFunding.class)

Relationship created successfully,but when i fetch crowdfunding object using neo4j template method,then it is coming.

My config is :

org.springframework.data:spring-data-neo4j:3.2.0.RELEASE

Upvotes: 0

Views: 138

Answers (1)

cybersam
cybersam

Reputation: 66957

Your query had probably created relationships to multiple User nodes from the same CrowdFunding node, since the query allows relationships to all User nodes with an ID in the {1} collection.

If this is indeed what you wanted, you would need to modify the Crowdfunding class to permit a collection of Users, like the following:

@NodeEntity
class CrowdFunding extends BaseEntity{
    String fundingFor
    String title

    @RelatedTo(type="HAS_USER")
    Collection<User> users
}

Upvotes: 3

Related Questions