I (as well as a whole lot of other Hibernate+JBOSS users, I guess) would love to see support in ME for managing/depolying JBOSS SAR modules (a SAR module is the recommended way of archiving/deploying Hibernate mapping files together with their associated class files for JBOSS).
My suggestion is that a Hibernate SAR project wizard is added to ME, and that the EAR project wizard/manager is enhanced with support for including a .sar archive in the .ear file.
The recommended way to layout a J2EE project that uses Hibernate with JBOSS is as follows:
myapp.ear/
META-INF/
application.xml
myapp.sar/ (Hibernate module)
/com/mycompany/classes
*.class
*.hbm.xml
/META-INF
jboss-service.xml
postgres-ds.xml
myapp.jar/ (EJB module)
...
myapp.war/ (Web module)
...
About SAR modules:
--------------------
A .sar module is a special type of module that upon deployment will be checked for XML files in it's META-INF directory.
When Jboss finds an XML file there, it will automatically try to deploy any services defined in that file.
This example module above defines a Hibernate SessionFactory service and the accompanying datasource (these could be defined in the same file, but are here in two different files for maintainability convenience).
When the above .sar module is deployed, JBoss will configure the datasource first (as the Hibernate SessionFactory service depends on it) and then start the SessionFactory service which will launch the standard Hibernate configuration process.
The nifty thing about this divition of modules is that the datasource that the Enterprise Project depends on can be included in the .ear and the sessionfactory service will be started automatically when deploying the .ear. Installing an enterprise application in JBoss is thus reduced to just dropping the .ear into the JBoss server/default/deploy directory. Also, the business objects managed by Hibernate are also likely to be used both by the EJB and the Web modules, and the Hibernate SAR module can thus be seen as a pure "business object" module - the EJB and Web modules just interact with it == redundancy is reduced.
jboss-service.xml:
-------------------
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<service>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=myapp/DataSource</depends>
<attribute name="JndiName">java:/myapp/HibernateFactory</attribute> (1)
<attribute name="Datasource">java:/myapp/DataSource</attribute> (2)
<attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute> (3)
<attribute name="MapResources"> (4)
com/mycompany/myapp/classes/User.hbm.xml,
com/mycompany/myapp/classes/Role.hbm.xml,
com/mycompany/myapp/classes/Permission.hbm.xml
</attribute>
<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UserTransactionName">java:/UserTransaction</attribute>
<attribute name="ShowSql">false</attribute>
</mbean>
</service>
|
Notes for jboss-service.xml:
------------------------------
Fields that (at least) should be controlled by the requested SAR project wizard/manager are
(1): the JNDI name of the service
(2): which datasource to use
(3): the hibernate dialect
(4): the list of Hibernate mapping files to load
postgres-ds.xml:
-------------------
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: postgres-ds.xml,v 1.1 2004/06/23 20:42:04 mica Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>myapp/DataSource</jndi-name>
<connection-url>jdbc:postgresql:myapp</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>scott</user-name>
<password>tiger</password>
</local-tx-datasource>
</datasources>
|
The .sar module is then referenced in the .ear/META-INF/application.xml file like this:
application.xml:
-----------------
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>MyApp</display-name>
<module id="myeclipse.1099526815609">
<web>
<web-uri>myapp.war</web-uri>
<context-root>/myapp</context-root>
</web>
</module>
<module id="myeclipse.1099275857859">
<ejb>myapp.jar</ejb>
</module>
<module id="myeclipse.1099524538796">
<java>myapp.sar</java>
</module>
</application>
|
---------------------------
Summary:
---------------------------
A Hibernate SAR project wizard should let you define
- the JNDI name of the SessionFactory service
- the JNDI name of the datasource to use
- the Hibernate dialect
- the list of Hibernate mapping files
- the datasource to be used by the SessionFactory service
Hope this info can help you in the development process if you decide to add the requested wizard/project type to ME - it would rock the JBoss + Hibernate world, just like ME is rocking the J2EE development process. Thanks for a superb J2EE IDE, probably the best available! (and hopefully soon-to-be even better!)
Regards,
Mikael.