Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ';运算符不存在';修改表中的项时出错_Java_Spring_Hibernate_Postgresql_Jpa - Fatal编程技术网

Java ';运算符不存在';修改表中的项时出错

Java ';运算符不存在';修改表中的项时出错,java,spring,hibernate,postgresql,jpa,Java,Spring,Hibernate,Postgresql,Jpa,我有两个DAO类与OneToMany关系绑定,如下面的代码片段所示 @Entity @Table ( name = “Parent_Result”) public class Parent { @Id @GeneratedValue @Column private Long Id; @Column private String value; @OneToMany(fetch = FetchType.EAGER, mappedBy =

我有两个DAO类与OneToMany关系绑定,如下面的代码片段所示

@Entity
@Table ( name = “Parent_Result”)
public class Parent {

    @Id
    @GeneratedValue
    @Column
    private Long Id;

    @Column
    private String value;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = “parentResult”, targetEntity = Child.class,
        cascade = Cascadetype.ALL)
    private set<Child> childSet;
}

@Entity
@Table ( name = “Child_Result”)
public class Child {

    @Id
    @Column
    @GeneratedValue
    private Long id;

    @Column
    private String result;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
    @JoinColumn(name = “parent_id”, referencedColumnName = “id”)
    private Parent parentResult;
}

public class ParentDal {

    @Autowired
    ParentRepository _parentRepo;

    @Autowired
    ChildRepository _childRepo;

    @transactional ( readOnly  =false, propogation = Propogation.REQUIRED)
    public void saveResults( Parent parentResult) {
        _parentRepo.saveAndFlush(parentResult);
        for(Child childResult : parentResult.getChildSet() ) {
            // Save parent PK in child. A requirement.
            _childRepo.saveOrUpdateParentIdInChild(parentResult.getId(),
                                                     childResult.getId());
        }
    }
}
似乎存储库类中的in'where'子句被当作字节数组,而它假定为bigint。正如提示中所建议的,我已经尝试将?2转换为bigint(如(2)和(3)注释中所示),但我被抛出了另一个异常,即bytearray不能转换为bigint

我被这个问题困扰了一天半。仍然不知道如何解决这个问题。请让我知道我在这里做错了什么。更新/删除失败的原因


编辑:

在发布我的问题之前,我还浏览了以下SO帖子:


你能尝试添加@OneToMany(fetch=FetchType.EAGER,mappedBy=“parentResult”,targetEntity=Child.class,cascade=Cascadetype.ALL)吗?对不起。编写此示例程序时,我没有放入mappedBy实体。我已经把它放在这里了。
public interface ChildRepository extends JpaRepository<Child, Long> {
     @Modifying
     @Transactional
     @Query(value = "update Child_Result set parent_id = ?1 where 
         id = ?2", nativeQuery = true)
         // id = (CAST( (?2) AS bigint))", nativeQuery = true) //-------> (2)
         // id = (?2::bigint)", nativeQuery = true)   //--------> (3)

     void saveOrUpdateParentIdInChild(Long parent_id, Long id);

}
[WARN] [30 Sep 21:55:18] - org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42883
[ERROR] [30 Sep 21:55:18] - org.hibernate.util.JDBCExceptionReporter - ERROR: operator does not exist: bigint = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.