站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Hibernate 专题更改osworkflow让其支持hibernate3

更改osworkflow让其支持hibernate3

摘要: 更改osworkflow让其支持hibernate3 问题分析: OSWorkflow2.7.0支持 hibernate2.1.8 问题一 :propertyset找不到对应的源码。在opensymp...
更改osworkflow让其支持hibernate3

  问题分析:
  
  OSWorkflow2.7.0支持 hibernate2.1.8
  
  问题一:propertyset找不到对应的源码。在opensymphony上下载到的代码与osworkflow中包含的propertyset包不一致。
  
  Osworkflow2.7.0自带的为propertyset-1.3-21Apr04.jar。而实际在主站中下载到的为propertyset1.3.jar
  
  其中在propertyset-1.3-21Apr04.jar(没有找到对应的源码)包中的
  
  DefaultHibernateConfigurationProvider包含成员变量和方法:
  
  Private net.sf.hibernate.cfg.Configuration configuration;
  
  Private com.opensymphony.module.propertyset.hibernate.HibernatePropertySetDAO propertySetDao;
  
  Private net.sf.hibernate.SessionFactory sessionFactory;
  
  Static synthetic java.lang.Class class$com$opensymphony$module$propertyset$hibernate$PropertySetItemImpl;
  
  方法:
  
  无参的构造函数
  
  public void setConfiguration(Configuration configuration);
  
  public Configuration getConfiguration();
  
  public HibernatePropertySetDAO getPropertySetDAO();
  
  public void setSessionFactory(SessionFactory sessionFactory);
  
  public void setupConfiguration(Map configurationProperties);
  
  static synthetic Class class$(String x0);
  
  而在opensymphony上下载到的DefaultHibernateConfigurationProvider的代码为:
  
  private Configuration configuration;
  
  private HibernatePropertySetDAO propertySetDAO;
  
  private SessionFactory sessionFactory;
  
  //~ Methods ////////////////////////////////////////////////////////////////
  
  public Configuration getConfiguration() {
  
  return configuration;
  
  }
  
  public HibernatePropertySetDAO getPropertySetDAO() {
  
  if (propertySetDAO == null) {
  
  propertySetDAO = new HibernatePropertySetDAOImpl(sessionFactory);
  
  }
  
  return propertySetDAO;
  
  }
  
  public void setupConfiguration(Map configurationProperties) {
  
  // loaded hibernate config
  
  try {
  
  configuration = new Configuration().addClass(PropertySetItem.class);
  
  Iterator itr = configurationProperties.keySet().iterator();
  
  while (itr.hasNext()) {
  
  String key = (String) itr.next();
  
  if (key.startsWith("hibernate")) {
  
  configuration.setProperty(key, (String) configurationProperties.get(key));
  
  }
  
  }
  
  this.sessionFactory = configuration.buildSessionFactory();
  
  } catch (HibernateException e) {
  
  }
  
  }
  
  另:
  
  类名与xml名的变化:
  
  PropertySetItem与PropertySetItem.hbm.xml
  
  在原有jar包中为PropertySetItemImpl和PropertySetItemImpl.hbm.xml
  
  解决办法:
  
  问题二:hibernate包名的变化分析
  
  hibernate2中包含expression包,而在hibernate3中则没有了。在hibernate3中多出来一个criterion包。
  
  Hibernate就在3.0的时候换上Antlr来解释HQL,使HQL的语法获得了加强。
  
  解决办法:
  
  问题三:osworkflow所需要的必要的jar包,我在更改osworkflow源码过程中,把webwork这部分去掉了,已解决,保证除了hibernate以外的其他部分可以正常便宜通过。尽量缩减需要更改的范围。然后把原先的jar解压,把更改的类重新覆盖对应的部分(只覆盖更改的部分),然后重新打包即可。这部分已解决!通过从CVS上获取最新代码可以解决。
  
  代码更改部分:
  
  propertyset更改方案:
  
  propertyset从CVS上获取最新代码,更改对应hibernate包内的所有引入的hibernate2改为hibernate3包。
  
  对于osworkflow从cvs上下载的代码更改HibernateWorkflowStore
  
  添加两个方法
  
  // add find method for this class by yunguang
  
  public List find(String queryString) throws StoreException {
  
  Query queryObject = session.createQuery(queryString);
  
  return queryObject.list();
  
  }
  
  public List find(String queryString, Object value) throws StoreException {
  
  Query queryObject = session.createQuery(queryString);
  
  queryObject.setParameter(0, value);
  
  return queryObject.list();
  
  }
  
  然后在此类中其他涉及到find方法的地方改到刚新加的find方法上,而hibernate2的find方法会多个type类型的参数,去掉即可。
  
  包名更改好,其他就没什么太大变动的地方,根据eclipse的错误提示一点一点改就可以了。
  
  问题解决备案:
  
  解决hibernate3的“System property org.xml.sax.driver not specified”异常错误。
  
  I got a SAXException("System property org.xml.sax.driver not specified")
  when I tried to run the SchemaExportTask.
  
  I solved the problem by installing jaxp. I then had to make sure that
  all the jars (dom.jar sax.jar xalan.jar xercesImpl.jar xsltc.jar)
  were in lib/endorsed under both my jdk installation root and my jre
  installation root.
  
  Hope that helps someone,
  Bobby
  
  so,in conclusion,in order to make it works as fine as you expected,you can do as the following ways to get an XMLReader:
  (1)
  XMLReader parser=XMLReaderFactory.createXMLReader(String className);
  (2)
  System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
  XMLReader parser=XMLReaderFactory.createXMLReader();
  (3)
  System.setProperty("org.xml.sax.parser","org.apache.xerces.parsers.SAXParser");
  XMLReader parser=XMLReaderFactory.createXMLReader();
  (4) more directly
  XMLReader parser=new org.apache.xerces.parsers.SAXParser();
  
  note that:
  1) in case (3),the parser is an instance of ParserAdaptor,it doesn't support the feture "http://xml.org/sax/features/validation",differented from the other cases.
  2) in case (2),the class you specified should implement the interface XMLReader, in case (3),the class you specified should implement the interface SAXParser.org.apache.xerces.parsers.SAXParser is applicable in both case.
  
  我是采用第二种办法解决的。
  
  WARN [(ehcache.config.Configurator)] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/tools/eclipse3.1/workspace/osworkflowfromcvs/lib/optional/ehcache.jar!/ehcache-failsafe.xml
  
  ERROR [(spi.hibernate.SpringHibernateFunctionalWorkflowTestCase)] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'osworkflowConfiguration' defined in class path resource [osworkflow-spring.xml]: Can't resolve reference to bean 'workflowStore' while setting property 'store'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowStore' defined in class path resource [osworkflow-spring.xml]: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [osworkflow-spring.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: antlr/ANTLRException
  
  解决办法将antlr的jar包加上就好了。
  
  解决hibernate2转移到hibernate3的
  
  ERROR [(org.hibernate.LazyInitializationException)] could not initialize proxy - the owning Session was closed
  
  通过跟踪代码可以发现,在创建sessionfactory是在org.springframework.orm.hibernate3.LocalSessionFactoryBean中的  protected SessionFactory newSessionFactory(Configuration config) throws HibernateException {
  
  return config.buildSessionFactory();
  
  }
  
  方法创建出来的。
  
  对于外界提供sessionfactor


↑返回目录
前一篇: 框架Hibernate Validator 简介
后一篇: 怎样利用Hibernate开发Blog实例分析