4

How do I use mysql's compress() and uncompress() functions to compress text before I store it and uncompress it when I retrieve it using a mysql database with hibernate for ORM?

ScArcher2
  • 85,501
  • 44
  • 121
  • 160

3 Answers3

6

See the ColumnTransformer, IIRC since 3.6:

@Column(name = "data", columnDefinition = "BLOB", nullable = false)
@ColumnTransformer(read = "UNCOMPRESS(data)", write = "COMPRESS(?)")
@Lob
public byte[] getData()
{
    return theData;
}
Claudio
  • 82
  • 2
  • 4
1

hmm native queries? But i dont have to tell you that your application will depend on a mysql rdbms then ;)

fasseg
  • 17,504
  • 8
  • 62
  • 73
0

A workaround would be to use stored procedures instead of queries. Stored procedures supported by hibernate. That's likely to get unwieldy, though.

eykanal
  • 26,437
  • 19
  • 82
  • 113