Results 1 to 7 of 7

Thread: Hibernate configuration using "mappingDirectoryLocations"

  1. #1
    Join Date
    Feb 2006
    Location
    Paris, France
    Posts
    13

    Default Hibernate configuration using "mappingDirectoryLocations"

    Hi everyone.

    My Hibernate configuration was previously made by entering all my *.hbm.xml in a "mappingResources" and it worked perfectly well.

    Because of maintenance problems, i've decided to switch to the "mappingDirectoryLocations" attribute and configure Hibernate that way :

    Code:
        <property name="mappingDirectoryLocations">
          <list>
            <value>classpath:/org/myspace/modele/configuration</value>
            ...
          </list>
        </property>
    But it doesn't work. I get the following exception :
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContextHibernate.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Mapping directory location [class path resource [org/myspace/modele/configuration]] does not denote a directory
    java.lang.IllegalArgumentException: Mapping directory location [class path resource [org/myspace/modele/configuration]] does not denote a directory
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:678)
    Note that if I change the classpath name to a name that doesn't exist, I get - luckily - a different exception (FileNotFoundException).

    Is thy my IDE that imply that problem ? Has anyone experienced such difficulties ? (i'm using Eclipse with Maven2)

    Thanks for your responses.

  2. #2
    Join Date
    Feb 2006
    Location
    Paris, France
    Posts
    13

    Default

    As my thread is the only one which has remained answerless since yesterday.
    So i give him another shot cause i still haven't solved my problem.

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

    Question Similar problem

    I have a similar problem. I have two application context files that define the dataSource and sessionFactory beans; one file for test and one for production. The production one (prod-datasource.xml, which works fine) has this:

    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <!-- setting production Hibernate properties here, blah, blah -->
      <property name="mappingDirectoryLocations"
        value="classpath:au/com/bisinfo/cmgr/logic"/>
    </bean>
    But in my test file (test-datasource.xml), if I used that format, no mapping files were found. I had to explicitly list each mapping file, like so:

    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <!-- setting test Hibernate properties here, blah, blah -->
      <property name="mappingResources">
        <list>
          <value>au/com/bisinfo/cmgr/logic/address/Address.hbm.xml</value>
          <value>au/com/bisinfo/cmgr/logic/country/Country.hbm.xml</value>
          <!-- repeat for 8 other mapping files -->
        </list>
      </property>
    </bean>
    It's ugly having to maintain this list of mapping files. Anyone know why the "mappingDirectoryLocations" approach doesn't work in my test cases (which extend AbstractTransactionalDataSourceSpringContextTests) ?

    Andrew

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

    Default Second problem now fixed

    Whoops ... after reading another thread I have successfully used this format in my test datasource.xml file:

    Code:
        <property name="mappingDirectoryLocations" value="file:target/classes"/>
    ... where "target/classes" is the Eclipse project folder that contains my root "au" package.

    Now, back to the original question, and apologies if I was thread-jacking...

  5. #5
    Join Date
    Feb 2006
    Location
    Paris, France
    Posts
    13

    Default

    Great, specifying one single classpath works for my case as well.
    Thanks.

  6. #6
    Join Date
    Jul 2008
    Posts
    1

    Smile

    Quote Originally Posted by dirtyhenry View Post
    Hi everyone.

    My Hibernate configuration was previously made by entering all my *.hbm.xml in a "mappingResources" and it worked perfectly well.

    Because of maintenance problems, i've decided to switch to the "mappingDirectoryLocations" attribute and configure Hibernate that way :

    Code:
        <property name="mappingDirectoryLocations">
          <list>
            <value>classpath:/org/myspace/modele/configuration</value>
            ...
          </list>
        </property>

    But it doesn't work. I get the following exception :
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContextHibernate.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Mapping directory location [class path resource [org/myspace/modele/configuration]] does not denote a directory
    java.lang.IllegalArgumentException: Mapping directory location [class path resource [org/myspace/modele/configuration]] does not denote a directory
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:678)
    Note that if I change the classpath name to a name that doesn't exist, I get - luckily - a different exception (FileNotFoundException).

    Is thy my IDE that imply that problem ? Has anyone experienced such difficulties ? (i'm using Eclipse with Maven2)

    Thanks for your responses.
    [Correct]
    <property name="mappingDirectoryLocations">
    <list>
    <set><value>classpath:/org/myspace/modele/configuration</value></set>
    ...
    </list>
    </property>
    [/Correct]

  7. #7
    Join Date
    Sep 2011
    Posts
    3

    Default

    Quote Originally Posted by Andrew Swan View Post
    Whoops ... after reading another thread I have successfully used this format in my test datasource.xml file:

    Code:
        <property name="mappingDirectoryLocations" value="file:target/classes"/>
    ... where "target/classes" is the Eclipse project folder that contains my root "au" package.

    Now, back to the original question, and apologies if I was thread-jacking...
    I m getting the same problem. I m not understand this."target/classes"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •