我已将pdf文件保存在数据库中。当我得到它时,看到错误。
@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
答案 0 :(得分:3)
使用它。
@Column( name = "CONTENT" )
@Lob(type = LobType.BLOB)
private byte[] content;
注意:以上方法取决于休眠版本,Lob注释可以没有类型参数。从这里引用:@Lob不再具有属性,猜测为lob类型(CLOB,BLOB)。如果基础类型是字符串或字符数组,则使用CLOB。使用othersise BLOB。