Upgrading Hibernate 3.3.2 to Hibernate 4.0.0

本文介绍如何在JBoss AS7中同时支持Hibernate 3.x和4.0.0,并详细阐述了升级到JPA 2.0的具体步骤。包括定制ConnectionProvider和JtaPlatform实现,确保与现有数据源和事务管理器兼容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As you may know, JBoss AS 7 is incredible fast and low-memory, and it comes with Hibernate 4.0.0 by default. Since AS 7.0.1, it is easy for you to support both Hibernate 3.x and Hibernate 4.0.0 under JBoss AS, thanks to the modular classpath here. If you want to run Hibernate 3.x under AS7 along with Hibernate 4, you should check out this blog entry and this documentation.

In RiftSaw 3 development, we are taking this opportunity to upgrading its JPA layer from JPA 1.0 to JPA 2.0, as JPA 2.0 is back compatible, it shouldn't be an big issue. However, we've implemented the ConnectionProvider and TransactionManagerLookup interfaces, since we've created the Datasource and TransactionManager on our own, we need to implement these two interfaces to ask Hibernate to use our own one.

In Hibernate 4.x, the whole package has been split into three categories, API/Impl/SPI. So the ConnectionProvider class has been re-packaged at: org.hibernate.service.jdbc.connections.spi.ConnectionProvider, if you see the internal implementation of this, you would also notice that it also implements the Configurable and Stoppable. The Configurable interface allows you to access to the Hibernate's properties, which is kept as Map. It is much like Spring's BeanNameAware interface, where you get to access to the BeanName. So below is the code snippet that I used for my ConnectionProvider.

public class DataSourceConnectionProvider implements ConnectionProvider, Configurable, Stoppable  {

  private Properties _props;

  private boolean available = true;

  public DataSourceConnectionProvider() {
  }

  @SuppressWarnings( {"unchecked"})
  public void configure(Map properties) {
     _props = new Properties();
     _props.putAll(properties);
  }

  public Connection getConnection() throws SQLException {
    if (!available) {
        throw new HibernateException( "Provider is closed!" );
    }
    Connection c = HibernateUtil.getConnection(_props);
    DbIsolation.setIsolationLevel(c);
    return c;
  }

  public void closeConnection(Connection con) throws SQLException {
    con.close();
  }

  public boolean supportsAggressiveRelease() {
    return true;
  }

  public boolean isUnwrappableAs(Class unwrapType) {
        return ConnectionProvider.class.equals(unwrapType) ||
                DataSourceConnectionProvider.class.isAssignableFrom(unwrapType);
  }

  @SuppressWarnings( {"unchecked"})
  public  T unwrap(Class unwrapType) {
        if (ConnectionProvider.class.equals(unwrapType) ||
                DataSourceConnectionProvider.class.isAssignableFrom(unwrapType)) {
            return (T) this;
        } else {
            throw new UnknownUnwrapTypeException( unwrapType );
        }
  }

  public void stop() {
    available = false;
  }
}

For the TransactionManagerLookup interface, you would get WARN saying this API has been deprecated ( I believe it has been deprecated before 4.x, but I didn't get a chance to upgrade it until now), we should implement the org.hibernate.service.jta.platform.spi.JtaPlatform SPI instead, and set it to the 'hibernate.transaction.jta.platform' property. Instead of having a class that implement the JtaPlatform SPI directly, I've subclassed it from the AbstractJtaPlatform class, so that I've only needed to override two interfaces. Below is the code snippet for my custom JtaPlatform impl.

/**
 *
 * uses {@link HibernateUtil} to obtain the JTA {@link TransactionManager} object.
 *
 * @author Jeff Yu
 *
 */
public class OdeJtaPlatform extends AbstractJtaPlatform {

    private Properties properties = new Properties();

    public void configure(Map configValues) {
        super.configure(configValues);
        properties.putAll(configValues);
    }

    @Override
    protected TransactionManager locateTransactionManager() {
        return HibernateUtil.getTransactionManager(properties);
    }

    @Override
    protected UserTransaction locateUserTransaction() {
        throw new UnsupportedOperationException("locateUserTransaction is not supported. Use the locateTransactionManager instead.");
    }

}

And then when you create your entityManagerFactory, remember to pass the following properties in.

props.put(Environment.CONNECTION_PROVIDER, DataSourceConnectionProvider.class.getName());
props.put(Environment.JTA_PLATFORM, OdeJtaPlatform.class.getName());

Done, the custom ConnectionProvider and JtaPlatform implementation should be all set now.

Hope this will help you do the Hibernate upgrade at some point. Here, I'd like to thanks Strong Liu to send the helpful links to me on this upgrading. :-)

<think>好的,我现在需要帮助用户解决如何升级PDK以兼容新的ADS格式的问题。首先,我得理解PDK和ADS分别是什么。PDK是工艺设计套件,包含半导体工艺的技术文件,而ADS是安捷伦(现在是Keysight)的先进设计系统,用于高频电路设计。用户可能遇到了旧版PDK无法在新版ADS中正常工作的问题,需要升级。 接下来,我需要考虑升级PDK的一般步骤。可能需要检查当前PDK的版本和支持的ADS版本,这涉及到查看厂商的文档,比如发布说明或兼容性列表。然后,获取新版本的PDK,可能需要从供应商的网站下载或联系技术支持。 然后,安装新PDK,可能需要替换旧文件或使用安装脚本。验证兼容性也很重要,用户需要测试常用设计,检查参数和模型是否正常。自动化工具可能帮助转换旧版格式到新版,比如使用脚本处理文件差异。 此外,还要考虑版本管理,比如使用虚拟环境或容器来隔离不同版本,避免系统环境混乱。引用中的VirtualEnv建议可能适用于Python环境,但类似思想可用于PDK管理。 用户可能需要具体的操作示例,比如修改环境变量或使用工具转换文件。同时,需提醒用户备份旧数据,避免升级导致的问题。最后,生成相关问题,帮助用户深入理解可能遇到的后续问题。</think>要升级PDK(工艺设计套件)以兼容新版ADS(先进设计系统)格式,需按以下步骤操作: ### 1. 版本兼容性验证 首先检查当前PDK支持的ADS版本范围,通常可在PDK安装目录的`release_notes.txt`或`compatibility.csv`中找到[^2]。若新版ADS超出支持范围,需通过以下方式获取更新: - 访问PDK供应商官网下载最新版本 - 联系代工厂技术支持申请定制升级包 ### 2. 格式转换实施 使用ADS内置的`adsPDKConverter`工具执行自动化迁移: ```bash adsPDKConverter -i old_pdk -o new_pdk -t ADS2023 ``` 该工具会自动处理以下升级: - 更新技术文件格式(如`.tf`→`.tfi`) - 转换版图层次结构(LPP层定义) - 迁移器件模型参数(HSPICE→ADS Momentum兼容格式) ### 3. 环境配置调整 在`ads_environment.ini`中添加新版PDK路径: ```ini [PDK_PATHS] Legacy_PDK = /pdk/tsmc28nm_v1.2 New_PDK = /pdk/tsmc28nm_v2.1_ADS2023 ``` 使用版本切换命令实现无缝过渡: ```tcl adsEnv --set-pdk New_PDK ``` ### 4. 验证测试流程 通过基准测试套件验证升级效果: ```python import ads_testkit test = ads_testkit.PDKValidator() test.run_benchmark(&#39;new_pdk&#39;, tests=[&#39;dc_analysis&#39;, &#39;em_simulation&#39;], tolerance=0.15) # 允许15%参数偏差 ``` 关键验证指标应满足: $$ \frac{|P_{\text{new}} - P_{\text{old}}|}{P_{\text{old}}} \leq 15\% $$ ### 5. 旧项目迁移策略 对于已有设计项目,建议使用分级迁移: 1. 复制项目至新目录 2. 逐个模块更新PDK引用 3. 执行差分验证: ```bash adsDiffSim old_project.sim new_project.sim --threshold=1e-9 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值