1

I'm trying to update the files in the Oracle Db with the help of following code

@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);
}

This is ServiceImpl

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

    }

Entity

@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;
        }
}

but am getting following error

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

please direct where i'm doing wrong.

user2582360
  • 55
  • 3
  • 13

1 Answers1

2

Refering to Inserting byte[] array as blob in Oracle Database getting ORA-01460: unimplemented or unreasonable conversion requested, I would suggest not to set the byte array as value but a ByteArrayInputStream wrapping your array.

Community
  • 1
  • 1
Smutje
  • 17,733
  • 4
  • 24
  • 41