Announcement Announcement Module
Collapse
No announcement yet.
Hibernate mapping locations within a jar? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate mapping locations within a jar?

    When specifying which hibernate mappings to use for a LocalSessionFactoryBean, I find it useful to avoid naming the mapping files explicitly and letting the classpath: find them. I can use the mappingDirectoryLocations flavor do find them based on directory location:
    Code:
    <property name="mappingDirectoryLocations">
      <list>
        <value>classpath&#58;com/mycompany/myapp/model/domain/</value>
      </list>
    </property>
    Unfortunately, it requires that the directory be mappable to the filesystem; it won't chase down mappings within a folder inside a jar on the classpath.

    I could use "mappingJarFileLocations", but I prefer not to name the location of the jar file explicitly either, and in some instances the mappings are not in a jar file (when running JUnit tests from my IDE with autobuild)

    Is there some way to allow specify the mappings on the classpath: (ideally by pattern matching) without naming them explicitly, whether they're in a jar or not?

    I'd like a way to keep a single orm config file that allows me to run in-container (when the mappings are in a jar); when unit testing within my IDE (when autobuild is keeping the mappings on its classpath); and from unit tests run by ant and driven by my continuous integration test tool.

    Spring being Spring, I'm betting on there being a way to achieve this that I've just not yet found.

  • #2
    try
    Code:
        <property name="mappingLocations">
          <value>classpath&#58;org/taha/domain/*.hbm.xml</value>
        </property>
    I am ot sure, I think it requires Spring 1.1.2
    HTH

    Comment


    • #3
      Thanks for the quick reply!

      I'd already tried that approach, however, and found that it didn't work.

      I just double-checked, it gives me this ex:

      Code:
      java.lang.IllegalArgumentException&#58; Could not convert location pattern &#91;classpath&#58;com/somecompany/model/domain/*.hbm.xml&#93; to Resource array
      I am using Spring 1.1.2

      Comment


      • #4
        I tried it before posting to the forum using files located in the classpath outside of jar. Unfortunately, I did not had the chance to try it with files inside a jar.

        Comment


        • #5
          Suddenly everyone wants to do this... I just posted a patch for PathMatchingResourcePatternResolver which allows for pattern matching Resources located inside jars.

          http://opensource.atlassian.com/proj...browse/SPR-469

          There's also a discussion on the dev list about a similar request in the thread "using *.xml for Hibernate mapping files in the spring.xml".

          Ollie

          Comment


          • #6
            Yes, it's 1.1.2. I verified that all the jars for the test are the 1.1.2 versions. I never use the $CLASSPATH environment var.

            This is a test that I am running from ant. I confirmed that the mapping files are in the jar on the classpath when the ant task is running. It does find them in the jar when I name them explicitly, but not with wildcards.

            This a domain model test suite run from ant. The entire model is in a jar, including the mapping files and the Spring context config files. The runtime config settings are all externalized into properties which are set for the test environment via a properties configurer.

            The test setUp consists of loading the config files using a ClassPathXMLApplicationContext. This has been working untouched apart from the experiment to move from explicit mapping names to the wildcard.

            I was optimistic about this working with 1.1.2 since there was a note in the release that suggested it would, although that note referred to mappings in a jar in an unexpanded war file. Is it possible that it's limited to the WebAppliicationContext?

            Comment

            Working...
            X