How is a blob column annotated in Hibernate?

前端 未结 2 1948
梦如初夏
梦如初夏 2020-12-09 07:59

How is a blob column annotated in Hibernate? So far I have a class that has:

@Column( name = \"FILEIMAGE\" )
private byte[ ] fileimage ;
//
public byte[ ] ge         


        
相关标签:
2条回答
  • 2020-12-09 08:36

    I used hibernate 4 in JBoss 7 and Java 7, and found out the BLOB column in my table doesn't work like what I have for hibernate 2. Fortunately, I solved it by reading other people solutions. My solution:

    1. Table in db, the column still defined in BLOB; change the hibernate mapping from type="blob" to type="binary"
    2. In Java getter/setter, using byte[] instead of BLOB (javax.sql)
    3. Change in the Java code which get and set this column properly. If involving InputStram, use byte[] to read/write to BLOB column; If reading from DB by using java.sql.ResultSet, make sure use getBytes() instead of getBlob() method.
    0 讨论(0)
  • 2020-12-09 08:39

    @Lob should do the trick for blob and clob (use String as type)

    @Column( name = "FILEIMAGE" )
    @Lob(type = LobType.BLOB)
    private byte[] fileimage;
    
    0 讨论(0)
提交回复
热议问题