Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy domain mapping

I have a to save a pdf report into an Oracle DB. The report's dataType is a byteArray.

The domain definition is as follows:

static constraints = {
 report(nullable:false)
 company(nullable:false)    
 month(nullable:false)    
}

byte[] report
Company company
Date month

}

Unfortunately this defines in the Oracle DB a field which has A RAW data_type and a lenghth of 255.

How should I define this field into the domain class? Should be defined as a BLOB?

If yes, How to do this?

Thanks in advance.

like image 885
Luixv Avatar asked Sep 07 '09 11:09

Luixv


3 Answers

255 is the default size provided to a byte[]. Specify the max size for report in constraints as per your requirement. Something like:

static constraints = {
    report(maxSize: 50000000)
}

Based on max size, the field type in DB will be set. (mediumblob, longblob etc.)

like image 196
Aman Aggarwal Avatar answered Oct 13 '22 22:10

Aman Aggarwal


Try explicitly setting the type to either a 'blob' or 'binary', for example you can add the following to the domain class:

static mapping = {
    report type:'blob'
}
like image 43
John Wagenleitner Avatar answered Oct 13 '22 20:10

John Wagenleitner


Here's a blog article that promises to solve this problem. The trick seems to be to have a field of type java.sql.Blob, with the byte[] field derived from that and marked as transient.

like image 33
Michael Borgwardt Avatar answered Oct 13 '22 21:10

Michael Borgwardt