Results 1 to 2 of 2

Thread: Spring/Hibernate under JBoss: SessionFactory choice

  1. #1
    Join Date
    Oct 2004
    Location
    Toulouse, France
    Posts
    19

    Default Spring/Hibernate under JBoss: SessionFactory choice

    Hi all,

    My Spring/Hibernate app is deployed under JBoss 4.0. Currently I use Spring transaction demarcation and a local SessionFactory which looks for the Hibernate configuration file:

    Code:
    <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory"
        class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <!-- Hibernate properties are centralized elsewhere -->
            <property name="configLocation">
                <value>classpath&#58;META-INF/hibernate.cfg.xml</value>
            </property>
        </bean>
    This works fine for unit tests outside the container. However, my app is deployed under the form of an EAR containing a HAR (JBoss archive format for Hibernated domain classes). This HAR contains a XML file named hibernate-service.xml describing the MBean:

    Code:
     <mbean code="org.jboss.hibernate.jmx.Hibernate"
    		name="jboss.har&#58;service=Hibernate">
    		<attribute name="DatasourceName">java&#58;/ds_1</attribute>
    		<attribute name="SessionFactoryName">java&#58;/hibernate/SessionFactory</attribute>
    		<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
    		<attribute name="CacheProviderClass">
    			net.sf.hibernate.cache.EhCacheProvider
    		</attribute>
    	</mbean>
    This file must define some Hibernate attributes (dialect, cache provider...) which overlaps with the hibernate.cfg.xml file used by my SessionFactory bean. I'm confused about which Hibernate parameters are used within JBoss. At a guess, I would say it depends on the SessionFactory:

    - if I use a local SessionFactory, Hibernate will be configured only with hibernate.cfg.xml. I get a unified behavior inside and outside the container but I lose the ability to use CMT demarcated transactions or define specific JBoss properties (TreeCacheProvider...).

    - if I use a JNDI SessionFactory, Hibernate will be configured only with hibernate-service.xml. I can switch from CMT to Spring managed transactions by changing only my TransactionManager bean (and my SLSB transaction attributes) but I must handle two different config files.

    Am I right on these points? For the moment we have no need for complicated transaction semantics (only one DB). Which strategy should I use?

    Thanks for your answers. Regards,
    Baptiste

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    We normally recommend using LocalSessionFactoryBean even if you want to use JTA (say, via Spring's transaction management over the top of JTA). Configuration of an O/R mapper should normally be part of your application, not part of the server configuration.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Replies: 4
    Last Post: Apr 2nd, 2008, 03:22 PM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 1
    Last Post: Jul 17th, 2005, 04:56 AM
  5. Replies: 3
    Last Post: Feb 5th, 2005, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •