Reputation: 188
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
Upvotes: 2
Views: 1128
Reputation: 15878
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.
Upvotes: 3