[旧作]我的技术架构之三-har之应用

       借助jboss的JBoss-hibernate技术,我们可以将hibernate的model和映射文件发布为一个har包.让jboss自行管理hibernate 的事务,是一个可以选择的方式:

1,通过middlegen或者其它hibernate的model和映射xml文件生成工具,生成相应的文件,并将其打包成.har文件,请在包中的META-INF目录下包含一个有如下内容的jboss-service.xml文件:


<server></server>
<mbean name="jboss.har:service=Hibernate" code="org.jboss.hibernate.jmx.Hibernate"></mbean>

<depends></depends>jboss.jca:service=DataSourceBinding,name=jdbc/JawaveSysPool
<attribute name="DatasourceName"></attribute>java:/jdbc/JawaveSysPool
<attribute name="Dialect"></attribute>org.hibernate.dialect.MySQLDialect

<attribute name="SessionFactoryName"></attribute>java:/hibernate/SessionFactory


<attribute name="CacheProviderClass"></attribute>org.hibernate.cache.EhCacheProvider

<attribute name="JdbcBatchSize"></attribute>20
<attribute name="MaxFetchDepth"></attribute>5

<attribute name="ShowSqlEnabled"></attribute>false

2,请在一个具有事务的容器类(这里采用SLSB)中通过如下代码访问:
....
SessionFactory _sf=(SessionFactory)new InitialContext().lookup("java:/hibernate/SessionFactory");
Session session=_sf.getCurrentSession();
...

3,请注意,将EJB配置成容器事务型,否则,你需要自己来处理事务了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值