Announcement Announcement Module
Collapse
No announcement yet.
Spring/Hibernate under JBoss: SessionFactory choice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X