【问题标题】:Can not set com.mysql.jdbc.Blob无法设置 com.mysql.jdbc.Blob
【发布时间】:2018-12-21 09:02:39
【问题描述】:

我已将 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

【问题讨论】:

    标签: java spring hibernate blob


    【解决方案1】:

    使用这个。

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

    注意 :上述方法依赖于休眠版本,Lob 注解可以没有类型参数。从这里引用:@Lob 不再具有属性,猜测 lob 类型(CLOB,BLOB)。如果基础类型是字符串或字符数组,则使用 CLOB。使用其他的 BLOB。

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 2020-09-03
      • 1970-01-01
      • 2014-04-27
      • 2015-12-26
      • 2018-08-02
      • 2011-12-06
      • 2011-03-13
      • 2019-10-07
      相关资源
      最近更新 更多