java - org.hibernate.HibernateException [org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.] -


i know may question asked before, difference of question using extended persistenceunit , not manage transaction server responsible manage it. btw using jpa(2.1) hibernate(4.3.10) provider, postgreesql(9.5) db , liberty server

this got in browser enter image description here

and here entities in simple view

@entity public class geoarea{       private integer id;//auto generated       private string name;        private set<tourismorganization> organizations;        //getter , setter methods        @manytomany(mappedby = "geoareas")       public set<tourismorganization> getorganizations() {           return organizations;       }         public void setorganizations(set<tourismorganization> organizations) {            this.organizations = organizations;        } } 

@entity public class tourismorganization{       private integer id;//auto generated       private string name;        private binarycontent logo;       private set<tourismgeoarea> geoareas;        //other getter , setter methods        @manytomany       public set<tourismgeoarea> getgeoareas() {           return geoareas;       }        public void setgeoareas(set<tourismgeoarea> geoareas) {          this.geoareas = geoareas;       }        @onetoone(fetch = fetchtype.eager, optional = true, cascade = { cascadetype.remove }, orphanremoval = true)       public binarycontent getlogo() {           return logo;       }        public void setlogo(binarycontent logo) {           this.logo = logo;       } } 

@entity public class binarycontent{     private integer id;//auto generated     private string contenttype;      private byte[] data;      //other getter , setter methods      @lob     @column(length = 16000000) // should generate medium blob     @basic(fetch = fetchtype.lazy) // i've read default, anyway...     public byte[] getdata() {         return data;     }      public void setdata(byte[] data) {         this.data = data;     }  } 

any idea how solve problem when getting organizations under geoarea using >> geoarea.organizations in xhtml page?

thanks

i know question asked before 1 month ago, want share solution no 1 answered here question.

btw solution use byte[] without @lob on getter generate column in postgre database table bytea , instead of oid column more

here code using avoid large objects may not used in auto commit mode .... exception fired in browser , prevent page working expected

@entity public class binarycontent{      private integer id;//auto generated      private string contenttype;       private byte[] data;       //other getter , setter methods       //@lob >> remember not using anymore avoid exception on browser      @column(length = 16000000) // should generate medium blob      @basic(fetch = fetchtype.lazy) // i've read default, anyway...      public byte[] getdata() {           return data;      }       public void setdata(byte[] data) {          this.data = data;      }  } 

note >> u must delete oid column hand if generated before using @lob if using hibernate.hbm2ddl.auto=update in persistence.xml not update column oid type bytea , consider oid fine sure can use hibernate.hbm2ddl.auto=create-drop drop , create tables again , generate column in bytea type


Comments