[旧作]我的技术架构之三-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配置成容器事务型,否则,你需要自己来处理事务了.

你可能感兴趣的:(Hibernate,jdbc,jboss,配置管理,ejb)