how to insert to BLOB field with persistent api
427038Jun 28 2008 — edited Aug 6 2008
Hi!
Ha have created a MySQL database with a few tables. One of tables has a LONGBLOB type.
the sql let it be:
CREATE TABLE IF NOT EXISTS `contract` (
`ContractID` INT NOT NULL AUTO_INCREMENT ,
`File` LONGBLOB NULL DEFAULT NULL ,
`Memo` LONGTEXT NULL DEFAULT NULL ,
PRIMARY KEY (`ContractID`) ,ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
After that with Netbans 6 I have created a database desktop aplication.
I have generated the entity classes from the databasee, and the master detail forms
public class Contract implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ContractID", nullable = false)
@Lob
@Column(name = "File")
private byte[] file;
@Lob
@Column(name = "Memo")
private String memo = "";
.........
In the GUI class : ClientMasterDetailForm after the file content is loaded in one byte[] variable I set for the entity object:
byte[] buff;
// initalaize anf load the buff
....
contract.setFile(buff);
When the user press the Save button, the folowing exception I have in log:
javax.persistence.RollbackException: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (7925431 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
Error Code: 0
When I use the "manual" jdbs connection I can create a prepared statament and set the blob value, but if I want tu use the persistent api, whitch is a Toplink from Oracle by feafault what can I do?
The file size can be from 1-2Mb to 50-100Mb. So I think is not the right solution to change the mysql variable to a big one.
Please post any idea what do you have and can be a solution!