Results 1 to 5 of 5

Thread: Cannot locate hibernate mappings files in jar

  1. #1
    Join Date
    Jul 2005
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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

  3. #3
    Join Date
    Mar 2005
    Posts
    1

    Default Same problem

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

    Thanks

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    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.

Similar Threads

  1. Replies: 3
    Last Post: Aug 22nd, 2006, 11:24 AM
  2. Replies: 8
    Last Post: Oct 6th, 2005, 04:04 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: Jan 19th, 2005, 11:22 PM
  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
  •