- This topic has 9 replies, 3 voices, and was last updated 19 years, 10 months ago by carniz.
-
AuthorPosts
-
carnizMemberI (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:
<pre>
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)
…
</pre>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:
——————-<?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 loadpostgres-ds.xml:
——————-<?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:
—————–<?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 serviceHope 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.
Riyad KallaMemberMikael,
What can I say but “Wow”, thank you for taking the time to post all this detail, I will file this enhancement request and include all your information in it so as to make it easier for the developers to assess.
carnizMemberA small correction:
the business object class files should be in a separate jar in order to be referable from a war archive (this is a class loader issue in JBoss).
The correct layout should thus look like this:
myapp.ear/ META-INF/ application.xml myclasses.jar /com/mycompany/classes foo.class bar.class myapp.sar/ (Hibernate module) /com/mycompany/classes foo.hbm.xml bar.hbm.xml /META-INF jboss-service.xml postgres-ds.xml myapp.jar/ (EJB module) ... myapp.war/ (Web module) ...
application.xml:
<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> <module id="myeclipse.1099334553452"> <java>myclasses.jar</java> </module> </application>
Riyad KallaMemberduley noted.
carnizMemberI have tried to reproduce the classloader issue mentioned above, but without success. This issue was posted by someone on a Hibernate doc wiki page so it could very well be that the particular user had messed up his/her application somehow.
The business objects can thus be packaged in the .sar module without problems, just as initially stated (I have verified this myself on JBoss 3.2.1, 3.2.3, 3.2.5 and 3.2.6) and be used both in EJBs and the web tier.
/Mikael
Eric McIntyreMemberWould LOVE to see this feature soon. My $.02….
A SAR can be used for any kind of “service” in JBoss, not just a Hibernate service. For instance, we are creating a SAR that watches a resource on one of our systems (an AS/400) and makes changes to an entity bean and writes notifications to a JMS topic. Currently, this has been possible to do in MyEclipse, though not as automated as I would like. If a SAR feature is added to MyEclipse, it should support Hibernate & non-Hibernate SAR’s. It should also support standalone deployment (similar to a WAR) and deployment as part of an EAR.
BTW, in JBoss 4 (and the last release of JBoss 3.2), a HAR (Hibernate ARchive) is a new special kind of SAR for Hibernate services. These projects should probably be treated a little differently from generic SAR projects – sort of a merging between a SAR project and a Hibernate project.
There’s some more information on the JBoss Wiki here and here
Eric
carnizMember@cybermac912 wrote:
BTW, in JBoss 4 (and the last release of JBoss 3.2), a HAR (Hibernate ARchive) is a new special kind of SAR for Hibernate services. These projects should probably be treated a little differently from generic SAR projects – sort of a merging between a SAR project and a Hibernate project.
A HAR is not capable of depolying eg a data source at the same time, why SAR is a better archive type as you then can deploy the whole application (EAR) just by dropping it in the deploy dir – no separate data source deployment/configuration needed. HAR is relatively new and *may* support this in the future, but OTOH, SAR is more all-round, and being a foundation archive type for JBoss it will always be supported. The main difference between SAR and HAR is that you don’t need to list the mapping files in the HAR descriptor, otherwise the info in the descriptors are pretty much the same, and feature-wise the SAR is more versatile.
/Mikael
Eric McIntyreMemberI can see your point. My own preference, though, would probably be to define two separate services: one for the HAR that defines both the Hibernate service and our Hibernate code/mappings; and one for resource-type stuff, like datasources, topics & queues, etc. I guess I like being able to put all the Hibernate-only stuff in one place. Not arguing, Mikael, just making sure the MyEclipse folks understand the different usage scenarios.
Eric
Eric McIntyreMemberBTW, JBoss 4.0 no longer supports resources like -ds.xml in the META-INF directory. They must be in the top-level of the SAR or another subdirectory (See thread on JBoss.org). JBoss 3.2 also allows the XML files to be in the top-level or other subdirectories.
carnizMember@cybermac912 wrote:
BTW, JBoss 4.0 no longer supports resources like -ds.xml in the META-INF directory. They must be in the top-level of the SAR or another subdirectory (See thread on JBoss.org). JBoss 3.2 also allows the XML files to be in the top-level or other subdirectories.
Thanks for the info. Most examples I’ve seen on the net have used META-INF as the location for *-ds.xml (best practice or not), but this has been on the JBoss 3.x series. If *-ds.xml (or other type of services) can be placed in other dir:s than META-INF also on the 3.x series, then there is no need for a (hopefully soon to be released ;-)) ME plugin to use that directory for datasources and such. This of course has to be confirmed as a working strategy for both the 2.x and the 3.x series before jumping on the “not in the META-INF dir” bandwagon. Otherwise, the plugin could just place *-ds.xml differently depending on the JBoss version used upon deployment, and that’s easily done (I presume).
/Mikael
-
AuthorPosts