2

I have saved pdf file in the database. When I get it , see the error.

@Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "CONTENT", nullable = false)
    private Blob content;

....

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/libsmanager] threw exception [Request processing failed; nested exception is org.hibernate.PropertyAccessException: Could not set field value [com.mysql.jdbc.Blob@65bb08cc] value by reflection : [class com.quangdat.entities.TrialBook.content] setter of com.quangdat.entities.TrialBook.content] with root cause
java.lang.IllegalArgumentException: Can not set com.mysql.jdbc.Blob field com.quangdat.entities.TrialBook.content to com.sun.proxy.$Proxy222

1 Answer 1

3

Use this.

@Column( name = "CONTENT" )
@Lob(type = LobType.BLOB)
private byte[] content;

NOTE : the above approach dependent on the hibernate version, the Lob annotation could have no type parameter. quote from here: @Lob no longer has attributes, the lob type (CLOB, BLOB) is guessed. If the underlying type is a String or an array of character then CLOB are used. Othersise BLOB are used.

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

Comments

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.