天天看點

JBPM4.4整合hibernate4所遇到的所有問題

 1.       問題1:

a)       報錯:

                       i.             java.lang.NoClassDefFoundError:org/hibernate/impl/SessionImpl

b)       原因:

                       i.             JBPM4預設使用的Hibernate3,Hibernate4中SessionImpl不再org/hibernate/impl包下;

                     ii.             當引用此包時,就會導緻找不到此類而報錯;

c)       錯誤所在類:

                       i.             在類org.jbpm.pvm.internal.wire.descriptor.HibernateSessionDescriptor中使用到了該類;

d)      解決:

                       i.             找到源檔案,修改SessionImpl的引用包為:

                     ii.             importorg.hibernate.internal.SessionImpl;

2.       問題2:

a)       報錯:

                       i.             java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

b)       原因:

                       i.             解決問題1,而附帶出來的問題;

                     ii.             因為Hibernate3中有方法sessionFactory.openSession(Connection),而在Hibernate4中     則沒有了此方法,進而導緻找不到;

c)       錯誤所在類:

                       i.             在類org.jbpm.pvm.internal.wire.descriptor.HibernateSessionDescriptor中使用到了該類;

d)      解決方法1:

                       i.             将該方法改為openSession(),不帶參數;

                     ii.             缺點:

1.       每次都客氣一個session,浪費;

e)       解決方法2:

                       i.             将該方法改為getCurrentSession(),同時*.cfg.xml中添加

                <propertyname="current_session_context_class">thread</property>

                     ii.             缺點:

1.       可能導緻問題Session was already closed

3.       問題3:

a)       報錯:

                 i.             Session was already closed;

b)       原因:

                       i.             使用了getCurrentSession()方法擷取session;

                     ii.             可能目前還沒有建立好session,而進行擷取,進而導緻的錯誤;

c)       錯誤所在類:

                       i.             在類org.jbpm.pvm.internal.wire.descriptor.HibernateSessionDescriptor中使用到了該類;

d)       解決方法1:

                       i.             換做openSession();

e)       解決方法2(還沒有實踐):

                       i.             使用getCurrentSession()擷取session,

                     ii.             如果整合Spring的話,使用Spring注入不出錯;

4.       問題4:

a)       錯誤:

                       i.             java.lang.NoSuchMethodError:org.hibernate.Hibernate.createBlob([B)Ljava/sql/Blob;      at org.jbpm.pvm.

b)       原因:

                       i.             JBPM4.4中使用的Hibernate3的Hibernate.createBlob()方法建立Blob大資料對象;

                     ii.             Hibernate4中取消了此方法,是以會導緻找不到該方法;

c)       錯誤所在類:

                   i.             org.jbpm.pvm.internal.lob.BlobStrategyBlob

d)      解決方法1:

                       i.             找到錯誤的類;

                     ii.             使用Hibernate4中提供的LobHelper#createBlob(bytes)方法生成Blob對象;

                   iii.             該類為SessionImpl類的内部類,需要通過SessionFactory對象擷取到該類,在通過session#getLobHelper()方法擷取;

e)       SessionFactory對象的擷取:

                       i.             通過直接讀取Spring配置檔案擷取;(注入報空指針):

1 2 3 4 5

ApplicationContext  factory = 

new

ClassPathXmlApplicationContext(

"applicationContext.xml"

);

SessionFactory sessionFactory =(SessionFactory)factory.getBean(

"sessionFactory"

);

LobHelper  lobHelper =

sessionFactory.openSession().getLobHelper();

                     ii.             直接代碼生成:

1 2 3 4 5 6 7 8 9 10

public

LobHelpergetLogHelper(){   

Configuration configuration =

new

Configuration();

configuration.configure(

"jbpm.hibernate.cfg.xml"

);

org.hibernate.service.ServiceRegistryserviceRegisy =

new

StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) .build();

SessionFactory sessionFactory=

configuration.buildSessionFactory(serviceRegisy);

LobHelper lobHelper =  sessionFactory.openSession().getLobHelper();

return

lobHelper;

}

5.       錯誤6:

a)       報錯:

                       i.             Error creating bean with name 'processEngine' defined in ServletContext resource [/WEB-INF/config/applicationContext_jbpm.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.jbpm.api.ProcessEngine org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()] threw exception; nested exception is java.lang.NullPointerException

b)       原因:

                       i.             在使用Spring4的時候,JBPM預設生成SpringProcessEngine類的時候,引用的是import org.springframework.orm.hibernate3.LocalSessionFactoryBean;包下的類;

c)       解決:

                       i.             該為引用hibernate4的包;

6.       問題6:

a)       報錯:

                       i.             擷取SessionFactory的時候為空;

b)       原因:

                       i.             使用的是注入的SessionFactory,每次确實注入了,但不知為什麼擷取不到;

c)       解決:

                       i.             在org.jbpm.pvm.internal.lob.BlobStrategyBlob類中,直接讀取Spring配置檔案,擷取SessionFactory,進而建立需要的執行個體;

1 2 3

ApplicationContextfactory = 

new

ClassPathXmlApplicationContext(

"applicationContext.xml"

);

SessionFactory sessionFactory =(SessionFactory)factory.getBean(

"sessionFactory"

);

LobHelper lobHelper =sessionFactory.openSession().getLobHelper();

7.       問題7:

a)       報錯:

                       i.             org.springframework.dao.DataIntegrityViolationException:Could not execute JDBC batch update; SQL [delete

b)       原因:

                       i.             JBPM4.4整合Spring後,所使用的資料庫方言問題,

c)       解決:

1

<

propkey

=

"hibernate.dialect"

>org.hibernate.dialect.MySQL5Dialect</

prop

>

改為

1

<

propkey

=

"hibernate.dialect"

>org.hibernate.dialect.MySQL5InnoDBDialect</

prop

>

8.問題8

  1. org.apache.jasper.JasperException: org.jbpm.api.JbpmException:   
  2.   error: parsing exception: expression factory class not found : javax.el.ELException: expression factory class not found

解決: 删除juel-api.jar包即可,因為它和tomcat的lib目錄下el-api.jar沖突 。即juel僅保留juel-impl.jar,juel-engine.jar即可。

參考自部落格http://lijiejava.iteye.com/blog/1934927,http://blog.51cto.com/fuyanchao/1614500