Announcement Announcement Module
Collapse
No announcement yet.
Cannot locate hibernate mappings files in jar Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot locate hibernate mappings files in jar

    We tried configuring the LocalSessionFactoryBean to locate the hibernate mapping files in a jar or directory. Neither seems to work. We get the error:

    java.io.FileNotFoundException: class path resource [classpath*:hibernate-mapping] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getU RL(ClassPathResource.java:147)
    at org.springframework.core.io.ClassPathResource.getF ile(ClassPathResource.java:154)
    at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .java:463)

    Here's how we tried to configure the sessionfactory:

    <property name="mappingJarLocations">
    <list>
    <value>classpath:hibernate-mappings.jar</value>
    </list>
    </property>

    where hibernate-mappings.jar was in the root of the ear

    and we tried:

    <property name="mappingDirectoryLocations">
    <list>
    <value>classpath*:hibernate-mapping</value>
    </list>
    </property>

    where the directory was in the root directory of the ear.

    Neither works. I saw in your posting that you got it to work with the directory on the file system. Am I doing something wrong? We also tried giving the absolute path of the directory and jar - that didn't work either.

  • #2
    Can you do that?

    I have always kept my mapping files within the WAR and listed them directly. Using classpath:/class.hbm.xml,classpath:/class1.hbm.xml etc.

    Are you sure it can load them from a jar? If so you might have to use the special jar notation which is something like (i.e. I can't remember exactly ):

    classpath:/myJar!classa.hbm.xml

    Just guessing though so don't take this too seriously

    Comment


    • #3
      Same problem

      Hi
      Have you been able to fix this issue?
      I am getting the same error.

      Thanks

      Comment


      • #4
        You must place your mapping files in a subdirectory. Do to limitations in the way java handles jar files, unfortunately, it's not possible to do a classpath* search for resources located in the root path of a jar/war etc..

        See the comments for PathMatchingResourcePatternResolver.

        HTH

        Ollie

        Comment


        • #5
          Oliver's right, but just to make it clear with a sample...
          For application contexts in the classpath at:

          /com/company/applicationContext.xml
          /com/company/applicationContext-ds.xml

          If they're in WEB-INF/classes the following will work:
          classpath*:**/applicationContext*.xml

          If they're in a JAR in WEB-INF/lib (for example) the following will work:
          classpath*:/com/**/applicationContext*.xml

          For anything in the root of a JAR, you can't use wildcards to load it.

          Comment

          Working...
          X