Java资源网

| JAVA基础 | 环境配置 | JDBC | 线程技术 | Socket编程 | JavaMail | JAVA与XML | 设计模式 | 技术新闻 | Java认证 | 程序人生 软件下载
| JSP&Servlet | Spring | Struts | Hibernate | JBuilder | Eclipse | WebService | EJB技术 | J2ME开发 | 应用服务器 | JXTA | Ajax
Articles search文章搜索
   关键字:
   类 别:
       
New download 最新下载
· [组件]HTML Parser 1.5
· [教程]WebSphere Studio应用教程
· [组件]JDom 1.0
· [工具]Junit3.8.1
· [教程]EJB编程及J2EE系统架构和设计
· [教程]EJB教程
· [教程]J2EE Tutorial中文版
· [教程]Java编程思想2(英文)
· [教程]java编程思想(完整版)
· [教程]Java网络编程
New articles 最新文章
· 设计移动 Web 服务
· 解析XML的时候完全忽略DTD
· 理解XML Schema XML Schema 初步
· 标签库的深入研究
· 提升JSP应用程序的七大绝招
· 如何使用JDOM对XML文件进行操作
· 处理XML字符串中特殊字符
· 利用Digester把XML转换成为Java对象
· 使用WebService 和RMI远程协作
· 使用Axis开发Web Service程序
Articles top 热门文章
· Eclipse基础--plugin插件安装(6644)
· eclipse+tomcat+lomboz的安装配置说明(4774)
· Java程序员就业前景(4584)
· Windows下JAVA环境变量的设置祥解(3788)
· Tomcat下JSP、Servlet和JavaBean环境的配置(3716)
· 使用links方式安装Eclipse插件(3698)
· 一个老程序员的心理话(3533)
· linux下jdk的安装与配置(3459)
· 初学者入门:Structs中基本配置入门(3334)
· Eclipse 运行命令行参数大全(3084)
您的位置:首页>>Hibernate>>更改osworkflow让其支持hibernate3
更改osworkflow让其支持hibernate3
2007-04-17   来源:www.javaresearch.org  作者:未知

  问题分析:
  
  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之映射继承关系四(图) (2007-04-17)
· 精通Hibernate之映射继承关系六 (2007-04-17)
· 精通Hibernate之映射继承关系八 (2007-04-17)
· 精通Hibernate之映射继承关系五 (2007-04-17)
· 精通Hibernate之映射继承关系二(图) (2007-04-17)
· 精通Hibernate之映射继承关系三 (2007-04-17)

版权所有©2005-2006 JAVA资源网 渝ICP备05007591号 虚拟主机 | 关于我们 | 联系方式 | 广告业务 | 网站地图 | 友情链接