4 Replies Latest reply on May 12, 2009 2:56 PM by Shervin Asgari

    File too big

    Shervin Asgari Master

      I have an entity called File which until recently I changed from 16MB byte to 100MB max. However it seems like it still thinks its 16MB which is max for the file.


      My entity bean:



      package no.kommuneforlaget.saksapp.model;
      
      import java.io.ByteArrayInputStream;
      import java.io.InputStream;
      import java.util.Date;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.Lob;
      import javax.persistence.PrePersist;
      import javax.persistence.Temporal;
      import javax.persistence.TemporalType;
      import javax.persistence.Transient;
      
      import no.kommuneforlaget.saksapp.process.FileReference;
      
      import org.hibernate.validator.NotNull;
      
      @Entity
      public class File {
      
           @Id @GeneratedValue
           private Long id;
           
           @NotNull
           @Column(nullable=false,length=256)
           private String name;
      
           @NotNull
           @Column(nullable=false,length=256)
           private String processKey;
           
           
           //BLOB = L + 2 bytes (max size is 2^16 - 1 or 65,535 bytes, 65KB)
           //MEDIUMBLOB = L + 3 bytes (max size is 2^24 - 1 or 16,777,215 bytes, 16MB)
           //LONGBLOB = L + 4 bytes (max size is 2^32 - 1 or 4,294,967,295 bytes, 4GB)
           //@Basic(LAZY) not needed since that is the default
           @Lob
           //Set to MAX 100MB MEDIUMBLOB in MySQL
           @Column(length=1024721500, nullable=false)
           private byte[] data;
      
           @Temporal(TemporalType.TIMESTAMP)
           private Date date;
           
           //@Temporal(TemporalType.TIMESTAMP)
           private Date emailedOn;
           
           @PrePersist //@PreUpdate - otherwise the create date will always be the same as the emailed date
           public void setDate() {
                date = new Date();
           }
      
           public void setEmailedOn(Date date) {
                emailedOn = date;
           }
      
           /**
            * Set the emailedOn property to now
            */
           public void setEmailedOnNow() {
                emailedOn = new Date();
           }
      
           @Transient
           public FileReference getReference() {
                if (date==null) {
                     date = new Date();
                }
                return new FileReference(name,id,date,emailedOn);
           }
           
           @Transient
           public InputStream getInputStream() {
                return new ByteArrayInputStream(data);
           }
           
           
           public Long getId() {
                return id;
           }
      
           public void setId(Long id) {
                this.id = id;
           }
      
           public String getName() {
                return name;
           }
      
           public void setName(String name) {
                this.name = name;
           }
      
           public String getProcessKey() {
                return processKey;
           }
      
           public void setProcessKey(String processKey) {
                this.processKey = processKey;
           }
      
           public byte[] getData() {
                return data;
           }
      
           public void setData(byte[] data) {
                this.data = data;
           }
      
           public Date getDate() {
                return date;
           }
      
           public void setDate(Date date) {
                this.date = date;
           } 
      
           public Date getEmailedOn() {
                return emailedOn;
           }
      
           @Transient
           public String cacheKey() {
                return "File:"+String.valueOf(id);
           }
      }
      


      My show create table File in the database:



      File  | CREATE TABLE 

      File

       (
        

      id
       bigint(20) NOT NULL auto_increment,
        

      name
       varchar(256) NOT NULL,
        

      processKey
       varchar(256) NOT NULL,
        

      data
       longblob NOT NULL,
        

      date
       datetime default NULL,
        

      emailedOn
       datetime default NULL,
        PRIMARY KEY  (

      id
      )
      ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8



      As you can see data has been changed from the previous mediumblob to longblob, however when I try to upload a file bigger than 16MB I get this error:



      Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (21985801 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.




      Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [no.kommuneforlaget.saksapp.model.File]
           at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
           at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
           at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)




      Now have I forgotten somewhere to update this? I have a create-drop on the database, so that shouldn't be a problem.


        • 1. Re: File too big
          Nicklas Karlsson Master

          Sounds like the driver complaining, show your persistence.xml

          • 2. Re: File too big
            Shervin Asgari Master

            persistence-dev.xml


            <?xml version="1.0" encoding="UTF-8"?>
            <!-- Persistence deployment descriptor for dev profile -->
            <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                         version="1.0">
                         
               <persistence-unit name="saksapp">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:/saksappDatasource</jta-data-source>
                  <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true"/>
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/saksappEntityManagerFactory"/>
                  </properties>
               </persistence-unit>
                
            </persistence>
            


            • 3. Re: File too big
              Nicklas Karlsson Master

              Configure the maxallowedpacket on the server side (google around). You might also have to pass it in as a property in persistence.xml if that doesn't cut it.

              • 4. Re: File too big
                Shervin Asgari Master

                Nicklas Karlsson wrote on May 12, 2009 13:28:


                Configure the maxallowedpacket on the server side (google around). You might also have to pass it in as a property in persistence.xml if that doesn't cut it.


                That worked!