java neo4j 创建节点_java – 如何在Spring数据neo4j中更新节点或节点实体?

Spring数据neo44中我们只有repository.save(实体),但是例如当我的UserEntity的属性(email)发生变化时,我不知道如何更新它.

我也尝试使用neo4j模板,但保存具有现有节点ID的实体导致下面的回滚.

org.springframework.dao.InvalidDataAccessApiUsageException: New value must be a Set, was: class java.util.ArrayList; nested exception is java.lang.IllegalArgumentException: New value must be a Set, was: class java.util.ArrayList

at org.springframework.data.neo4j.support.Neo4jExceptionTranslator.translateExceptionIfPossible(Neo4jExceptionTranslator.java:43)

at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)

at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)

at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

我们如何更新节点或节点实体?

public void updateUserNode(UserEntity user) {

try{

UserEntity updatedUser = this.getUserByUserId(user.getUserId());//finding node with user id///

updatedUser.setEmail(user.getEmail());

updatedUser.setImageId(user.getImageId());

updatedUser.setFirstname(user.getFirstname());

updatedUser.setLastname(user.getLastname());

//System.out.println("Deleting ");

//userRepository.delete(del);

System.out.println("UPDATING ");

// with existing Id, you can not save it again/, or update

updatedUser = userRepository.save(updatedUser);

}catch(Exception e){

e.printStackTrace();

}

//return

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值