我正在尝试通过以下代码来更新Oracle Db中的文件

@RequestMapping(value = "/person/{personId}", method = RequestMethod.POST)
    public @ResponseBody String save(@RequestParam MultipartFile files,@PathVariable int personId,) throws IOException {

        byte [] bFile =files.getBytes();
        personService.uploadImageOnId(personId,bFile);
}


这是ServiceImpl

@Override
public void uploadImageOnId(int personId,byte [] personImage) {
        entityManager.createNamedQuery("Person.uploadImageOnId")
                .setParameter("personId", personId).setParameter("personImage", personImage)
                .executeUpdate();

    }


实体

@Entity
@Table(name = "PERSON")
@NamedQueries({
@NamedQuery(name = "Person.uploadImageOnId", query = "UPDATE Person p SET p.personImage= :personImage WHERE p.personId= :personId" )

})
public class Person implements java.io.Serializable {
    @Column(name="PERSON_IMAGE")
        @Lob
        private byte[] personImage;

        public byte[] getPersonImage() {
            return personImage;
        }

        public void setPersonImage(byte[] personImage) {
            this.personImage = personImage;
        }
}


但出现以下错误

java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;


请指出我做错了的地方。

最佳答案

提到,我建议不要将字节数组设置为值,而应使用ByteArrayInputStream包装数组。

09-27 00:50