13 Replies Latest reply on Jul 8, 2014 10:38 PM by gbadner

    Error when persisting a lob

    cmartin39

      I am getting an error when i try to persist an Lob. Does anyone know what this error means?

       

      Caused by: java.lang.IllegalArgumentException: interface org.hibernate.engine.jdbc.BlobImplementer is not visible from class loader

              at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:487) [rt.jar:1.7.0_45]

              at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:722) [rt.jar:1.7.0_45]

              at org.hibernate.engine.jdbc.BlobProxy.generateProxy(BlobProxy.java:176)

              at org.hibernate.engine.jdbc.NonContextualLobCreator.createBlob(NonContextualLobCreator.java:50)

              at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.unwrap(SerializableTypeDescriptor.java:118)

              at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.unwrap(SerializableTypeDescriptor.java:44)

              at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$4$1.doBind(BlobTypeDescriptor.java:133)

              at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:90)

              at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286)

              at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:281)

              at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:56)

              at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2843)

              at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3121)

              at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)

              at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)

              at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)

              at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:349)

              at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)

              at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)

              at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222)

              at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)

              at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:110)

              ... 24 more

       

      My persistence class is:

      public class FooEntity implements Serializable {   

          private static final long serialVersionUID = 1L;

          private String name;

       

          @Id

          @GeneratedValue

          private Long id;

         

          @Column(nullable = false)

          private Date timeStamp;

       

          @Lob

          private Foo message;

          private String address;

       

          public VehicleStatusWrapperEntity() {

          }

         

          public VehicleStatusWrapperEntity(Foo message) {

              this.message = message;

          }

       

          public String getName() {

              return name;

          }

       

          public void setName(String name) {

              this.name = name;

          }

       

          public void setId(Long id) {

              this.id = id;

          }

       

          public Long getId() {

              return id;

          }

         

          public String getAddress() {

              return address;

          }

         

          public void setAddress(String address) {

              this.address = address;

          }

         

          public Foo getMessage() {

              return message;

          }

         

          public void setMessage(Foo message) {

              this.message = message;

          }

       

          public void setTimeStamp(Date timeStamp) {

              this.timeStamp = timeStamp;

          }

       

          public Date getTimeStamp() {

              return timeStamp;

          }

      }

        • 1. Re: Error when persisting a lob
          sfcoy

          Do you have Hibernate jars in your WEB-INF/lib directory?

          • 2. Re: Error when persisting a lob
            cmartin39

            Yes i do.

            • 3. Re: Error when persisting a lob
              sfcoy

              Make sure that you have covered everything off in the JPA Reference Guide, especially if you you're using an older version of Hibernate.

               

              I recommend dispensing with your own jars and just using the server provided JPA implementation, though.

              • 4. Re: Error when persisting a lob
                sfcoy

                By the way, you may want to consider adding:

                @Basic(fetch=LAZY)
                @Lob
                private Foo message;
                

                if Foo objects can be arbitrarily large.

                 

                Load them explicitly with a query when you need them.

                 

                This will reduce scaling problems.

                • 5. Re: Error when persisting a lob
                  cmartin39

                  The Foo object is not arbitrarily large.

                   

                  I tried to simplify the problem

                  when i have message

                   

                       private String message;

                   

                  It works fine but when i change it to

                   

                       @Lob

                       private String message;

                   

                  It throws the same error.

                  • 6. Re: Error when persisting a lob
                    smarlow

                    Which version of Hibernate jars are included in the application?  Does removing the Hibernate jars have any impact on this problem? 

                     

                    From looking at the Hibernate source code, we should be using either the application classloader or the Hibernate classloader.  In your case, we might be using a different classloader than we need to.

                    • 7. Re: Error when persisting a lob
                      cmartin39

                      Im including 4.1.6. I have the same problem when i remove the jars. I found a workaround but not sure why i need to do it. I have a mdb that calls my persistence class. When i add @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) to the method that is doing the persist the error does not happen

                      • 8. Re: Error when persisting a lob
                        smarlow

                        I'm not sure why your workaround helped.  Have you considered getting the Hibernate source from github and debugging the org.hibernate.engine.jdbc.BlobProxy class to see what getProxyClassLoader() is returning.

                         

                        gbadner, any suggestions?

                        • 9. Re: Re: Error when persisting a lob
                          qsp

                          I am also observing this behaviour (Exceptions and rollback when persisting Lob) and solved the issue with the annotation " @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) " on the JMS consumer method.

                           

                          I'm using Wildfly 8.0.0.Final on the openshift platform.

                           

                           

                          Error occurred after changing the persistence data source from a in-memory H2 database to the PostgreSQL database. Lobs where persisted correctly in the H2 database without the annotation.

                           

                          Unfortunately I don't have enough time to try your suggestion (Debug BlobProxy) at the moment. Maybe this information could help understanding the problem and/or help others with the workaround.

                           

                          I'm using the hibernate provided by the Application Server:

                           

                          qsp@HP:~/openshift/wildfly8/deployments$ jar tf pesti-ear-1.0-SNAPSHOT.ear

                          META-INF/

                          META-INF/MANIFEST.MF

                          lib/

                          pesti-svc-1.0-SNAPSHOT.war

                          META-INF/application.xml

                          META-INF/glassfish-application.xml

                          META-INF/jboss-app.xml

                          pesti-web-1.0-SNAPSHOT.war

                          lib/commons-io-2.4.jar

                          lib/pg-1.50.0.0.jar

                          lib/pesti-crypto-1.0-SNAPSHOT.jar

                          lib/core-1.50.0.0.jar

                          lib/prov-1.50.0.0.jar

                          lib/jackson-mapper-asl-1.9.7.jar

                          lib/commons-codec-1.6.jar

                          lib/json-20080701.jar

                          lib/httpcore-4.3.2.jar

                          lib/commons-lang-2.6.jar

                          lib/commons-lang3-3.2.1.jar

                          lib/commons-logging-1.1.3.jar

                          lib/httpclient-4.3.3.jar

                          lib/jackson-core-asl-1.9.7.jar

                          pesti-ejb-1.0-SNAPSHOT.jar

                          META-INF/maven/

                          META-INF/maven/com.unfoldingtech/

                          META-INF/maven/com.unfoldingtech/pesti-ear/

                          META-INF/maven/com.unfoldingtech/pesti-ear/pom.xml

                          META-INF/maven/com.unfoldingtech/pesti-ear/pom.properties

                          • 10. Re: Re: Error when persisting a lob
                            smarlow

                            Hard to help without a test case but I suspect that a sub-deployment (in your ear), has the hibernate classes on its classpath but the top level classloader (representing the ear) doesn't.  The sub-deployment that has the persistence.xml should have the Hibernate dependencies automatically added.

                             

                            Do you have time to tinker with adding the org.hibernate module dependency to your EAR sub-deployments?  You could do this by adding a "Dependencies: org.hibernate" manifest entries to sub-deployments (see some documentation here.)  Let us know if that helps or not.

                             

                            Also, add "Dependencies: org.hibernate" to the EAR (top level) as well.  I meant to include org.hibernate instead of javassist. 

                            • 11. Re: Re: Error when persisting a lob
                              qsp

                              It could be the problem indeed.

                               

                              I can confirm that:

                               

                                  - EAR: pom.xml doesn't contain hibernate or persistence dependencies.

                                        - EJB: pom.xml depends on org.eclipse.persistence

                               

                              There are no explicit dependencies on hibernate because the project was originally running in glassfish, and after reading Migrating a Java EE App from GlassFish to WildFly · WildFly I think i shouldn't be using them.

                               

                              I'll clear up the dependencies to include only javax.persistence and get back to you…

                               

                              Thank you for your reply.

                              • 12. Re: Re: Re: Error when persisting a lob
                                smarlow

                                To test my theory, I think that you could add a MANIFEST.MF to the top level of the EAR (META-INF/MANIFEST.MF) and include a:

                                Dependencies: org.hibernate export

                                Which should export the Hibernate dependency to all sub-deployments also.  If this helps, we can create a jira for the issue to fixed in code (so that you won't have to workaround this in the future).

                                • 13. Re: Re: Error when persisting a lob
                                  gbadner

                                  This should be fixed by [HHH-8310] SerializableBlobProxy.getProxyClassLoader WrappedBlob class loading problem - Hibernate JIRA in 4.3.6.

                                   

                                  Scott, thanks for bringing this to my attention.