How is a blob column annotated in Hibernate? So far I have a class that has:
@Column( name = "FILEIMAGE" )
private byte[ ] fileimage ;
//
public byte[ ] getFileimage ( ) { return this.fileimage ; }
public void setFilename ( String filename ) { this.filename = filename ; }
@Lob should do the trick for blob and clob (use String as type)
@Column( name = "FILEIMAGE" )
@Lob(type = LobType.BLOB)
private byte[] fileimage;
Mingwei Wu
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:
- Table in db, the column still defined in BLOB; change the hibernate mapping from
type="blob"totype="binary" - In Java getter/setter, using
byte[]instead ofBLOB(javax.sql) - Change in the Java code which get and set this column properly. If involving InputStram, use
byte[]to read/write toBLOBcolumn; If reading from DB by usingjava.sql.ResultSet, make sure use getBytes() instead ofgetBlob()method.
来源:https://stackoverflow.com/questions/939673/how-is-a-blob-column-annotated-in-hibernate