Results 1 to 4 of 4

Thread: How do you swap dev/prod session factories for integr test?

  1. #1
    Join Date
    Aug 2004
    Posts
    1,905

    Default How do you swap dev/prod session factories for integr test?

    Hi all,

    At the moment I am unit testing my DAOs by manually constructing the sessionFactory and injecting it. I have been looking at the spring integration tests, but I cannot figure out how to manage the seperate contexts.

    I *could* add all the component contexts and include the development-persistence.xml and *exclude* the applicationContext.xml, but there are other beans in appContext.

    What do other people do? Do you have an aenmic appContext which just imports other context?

    Thanks all.

    Col

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

    Default

    People normally factor the persistence related stuff (datasource, transaction manager) into a separate XML doc like persistence-test.xml and persistence-deploy.xml. SessionFactory is usually common, just referencing/referenced by those shared beans, but you may have sep hbm.xml files I guess and this approach also accommodates them.

    This XML file is one of those assembled into a single context. All the other XML definitions will normally be the same in both environments.

    HTH,
    Rod
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Right, I think I got myself all confused because my sessionFactory includes a configLocation which indicates a datasource (for hibernate), but I also have a dataSource defined in the context.xml as well (from JNDI).

    So I remove the datasource from my context and provide a development hibernate.cfg.xml for unit tests (the sessionFactory.configLocation is classpath:hibernate.cfg.xml).

    Thanks Rod.

  4. #4
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Lightbulb Hibernate dialects might also differ between prod/test

    Note that if you use different DB types in test and production (e.g. your tests use an HSQL in-memory db), you will also need to factor the sessionFactory bean definition out into separate test/prod XML files, because part of the sessionFactory definition is the hibernate.dialect property, which of course needs to be set to different values for the two db products in question.

Similar Threads

  1. OpenSessionInView and portlet support
    By garpinc2 in forum Web Flow
    Replies: 31
    Last Post: Apr 9th, 2010, 11:12 AM
  2. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Replies: 1
    Last Post: Mar 12th, 2005, 04:33 AM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 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
  •