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.

6
  • Which method call with which acutal parameters cause the exception? Commented Feb 15, 2014 at 9:50
  • What if you use Byte instead of byte in your Entity ? Commented Feb 15, 2014 at 10:00
  • @Smutje .setParameter("personImage", personImage) here it is pointing error Commented Feb 15, 2014 at 10:03
  • Well personImage is not an object so that might be it, can you try to use Byte[] ? Commented Feb 15, 2014 at 10:03
  • @Pierre getting same error Commented Feb 15, 2014 at 10:07

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this on ur suggestion .setParameter("personImage", new ByteArrayInputStream(personImage)) but am gettin exception
we cant use setBinaryStream in createNamedquery
is der any other way of doing this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.