我正在尝试在以下代码的帮助下更新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);
}
这是服务输入
@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;
请指出我做错的地方。
参考在
Oracle 数据库中将 byte[] 数组作为 blob 插入 获得 ORA-01460:请求未实现或不合理的转换,我建议不要将字节数组设置为值,而是包装数组ByteArrayInputStream
。