-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Can deployment be improved ?
PostPosted: Fri Nov 21, 2003 5:25 am 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Hi,

I'm looking at using Hibernate for multiple web applications running in JBoss. I set up JBoss / sar OK but noticed that the ..jmx.HibernateService only supports .hbm.xml files (and all my mapping files are in a jar - because there's loads of them). So I modified HibernateService as follows:

in buildSessionFactory()

160: if(mappingFiles[i].endsWith(".jar"))
161: cfg.addJar(mappingFiles[i]);
162: else
163: cfg.addResource(mappingFiles[i], Thread.currentThread().getContextClassLoader());

This worked fine (for me anyway) provided the sar is set up as a directory rather than an archive (otherwise the jar is not found).

However, I realised that I can no longer just hot deploy a .war file into JBoss, but will have to copy all the application class files and mapping jars to the sar directory and restart the server (or at least the service through the JMX console).

This seems a bit of a drawback, but I can't see anyway around it apart from creating the SessionFactory within each application (I've reluctantly adopted this approach).

What would be really nice is to add the mappings / classes to the SessionFactory held in JNDI as the web app is deployed, rather than at boot time. This is not currently possible as SessionFactory is immutable.

Has this been discussed before, and if so what was the out come ? If not , does it make sense and how could it be done ?

I'm happy to write some code if it would be of use, but this seems to be quite a significant architectural change (and I don't want to waste any time :-) so any advice from those more familiar with Hibernate would be really appreciated.

Regards,
Greg.

PS I'm not quite sure how to propose a patch for the "addJar" code - how do I do this ?

_________________
Greg Hall


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Maybe I dont understand your problem but ... the JMX service MBean will look for the hbm files in the sar archive using the mapping file description/path. There is no need to unpack the SAR files for the service to find them.

In anycase, FYI, patches are created using your CVS client and sent to JIRA for consideration.


Top
 Profile  
 
 Post subject: A bit more info
PostPosted: Fri Nov 21, 2003 5:43 pm 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Initially I didn't want to have to write all the *.hbm.xml file names in the <attribute name="MapResources"> element of the MBean descriptor. Providing the add jar method solved that.

The more important point is that all the resources (mapping files and class files) have to be specified in the MBean descriptor, which means that I can't hot deploy a web application and I now have to add the resources to the sar as well as the war / ear. This seems a bit messy, particularly as I have multiple web apps running on the same server.

I think Hibernate is brilliant, it just doesn't seem easy to fit it into an App. server like JBoss.

Regards,
Greg

_________________
Greg Hall


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I have code sitting on my box (untested) for solving this, if I understand your problem correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:06 pm 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Excellent - looking forward to seeing it :-)

_________________
Greg Hall


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 9:43 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Hibernate XDoclet solves all this.

We have Ant targets that generate the hbm.xml's and jboss-service.xml, create the SAR, and hot deploy it to JBoss. Works like a dream, and with the new ASM library, is very quick to deploy.


Cheers,


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 1:29 pm 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Thanks for that - very useful.

A couple of questions though (as I haven't used XDoclet much) :

Does this still work if the mapping files are not generated by XDoclet ?
(I use a code generator to produce my Java files, Hibernate Mappings and Database schema from a simple specification language).

Where are the mapping files listed in the jboss-service.xml "MapResources" attribute specified ? Is this the mergeDir ?

Do you have an example of this you could post ?

Thanks again for your help,

Regards,
Greg.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 4:11 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
The whole idea of the Hibernate XDoclet task is that metadata included in the Java source is used to create the mapping files and the jboss-service.xml. You can then jar these up into a SAR with the class files, and away you go.

Code:

    <!-- =================================================================== -->
    <!-- generates the hibernate HBM.XML files and SAR descriptor           -->
    <!-- =================================================================== -->

   <target name="generate-Hibernate"
           description="Generates Hibernate class descriptor files."
           depends="compile">

      <!-- copy additional resources for the Hibernate XDoclet task to the
          mergedir   -->
      
           <fileset dir="${src.dir}">
               <include name="**/hibernate/hibernate-properties-*.xml"/>
           </fileset>
        </copy>
   
       <!-- Execute the hibernatedoclet task -->
       <hibernatedoclet
           destdir="${build.resources}/sar/hibernate"
            excludedtags="@version,@author,@todo,@see,@desc"
            addedtags="@xdoclet-generated at ${TODAY}@copyright Galenworks,@author Galenworks,@version ${version}"
           force="${xdoclet.force}"
           mergedir="${build.resources}/sar/hibernate"
           verbose="false">
      
           <fileset dir="${src.dir}">
               <include name="**/hibernate/*.java"/>
           </fileset>
      
           <hibernate version="2.0"/>
          
           <jbossservice
                destdir="${build.resources}/sar/hibernate"
              serviceName="Hibernate"
                jndiName="${hibernate.jndi.name}"
                dataSource="${hibernate.datasource.name}"
                dialect="${hibernate.dialect}"
                useOuterJoin="true"
                transactionManagerStrategy="net.sf.hibernate.transaction.JBossTransactionManagerLookup"
                transactionStrategy="net.sf.hibernate.transaction.JTATransactionFactory"
                userTransactionName="UserTransaction"
           />
      
       </hibernatedoclet>
   

    </target>



The jbossservice tag in there creates the jboss-service.xml with all the generated hbm.xml file names in the MapResources, relative to the destdir of the main hibernatedoclet tag.

Now create the SAR:

Code:
   
    <target depends="generate-Hibernate" name="hibernate-sar">
      
        <jar destfile="${build.lib}/galenworksHibernateStartup.sar">
         
            <!-- Get the generated hbm.xml files  -->
            <fileset dir="${build.resources}/sar/hibernate">
                <include name="**/*.hbm.xml"/>
            </fileset>
           
            <metainf dir="${build.resources}/sar/hibernate">
                <include name="jboss-service.xml"/>
            </metainf>
        </jar>

        <antcall target="hibernate-schemaexport" />
       
    </target>



The hibernate-schemaexport target is:


Code:
    <!-- =================================================================== -->
    <!-- Generate the database creation scripts from the Hibernate schema.   -->
    <!-- =================================================================== -->
    <target name="hibernate-schemaexport">
        <taskdef name="schemaexport"
                 classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
            <classpath>
                <fileset dir="${lib.dir}">
                   <include name="hibernate2.1b6.jar"/>
                   <include name="cglib-asm.jar"/>
                   <include name="commons-collections.jar"/>
                   <include name="commons-beanutils.jar"/>
                   <include name="commons-lang.jar"/>
                   <include name="commons-logging.jar"/>
                   <include name="dom4j.jar"/>
                   <include name="jaas.jar"/>
                   <include name="jcs.jar"/>
                   <include name="jdbc2_0-stdext.jar"/>
                   <include name="dom4j.jar"/>
                   <include name="jaas.jar"/>
                   <include name="jcs.jar"/>
                   <include name="jdbc2_0-stdext.jar"/>
                   <include name="odmg.jar"/>
                </fileset>
                <fileset dir="${build.lib}">
                    <include name="galenworksHibernateStartup.sar" />
                    <include name="galenworksCommon.jar" />
                </fileset>
            </classpath>
        </taskdef>
                 
        <schemaexport output="${basedir}/${build.resources}/drop-and-build.sql"
                   properties="${hibernate.connection.config}"
                   quiet="yes"
                   delimiter=";"
                      text="yes">
            <fileset dir="${build.resources}/sar/hibernate">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </schemaexport>

                 
        <schemaexport output="${basedir}/${build.resources}/drop.sql"
                   properties="${hibernate.connection.config}"
                   quiet="yes"
                   drop="yes"
                   delimiter=";"
                      text="yes">
            <fileset dir="${build.resources}/sar/hibernate">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </schemaexport>

    </target>


This gives the base database creation scripts. We have some additional scripts that build indexes, stored procedures etc, that we build by hand.


So, if you can generate the Java source with Hibernate XDoclet tags, you could have XDoclet do the rest for you.


Cheers,


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 5:48 pm 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Sherman, your a star :-)

I need to change my code generator, but I will certainly give this a go.
Thanks again.

Gavin,
How does this method (using XDoclet) compare with the code the you have "sitting on your box" ? Are you able to give us any info ?

Regards,
Greg.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What I have doesn't use XDoclet. It scans the deployed jar or directory.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 10:31 am 
Newbie

Joined: Fri Nov 21, 2003 4:53 am
Posts: 6
Location: London, UK
Gavin,
Any idea when it will be available ?

I've a really big project that I want to use Hibernate for (currently in design), and I would love to settle this issue before I start building.

Regards,
Greg.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.