Results 1 to 9 of 9

Thread: Question on classloaders and Hibernate hbm.xml files

  1. #1
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default Question on classloaders and Hibernate hbm.xml files

    I have an application that is using hibernate. In my bean def file I am using the org.springframework.orm.hibernate.LocalSessionFact oryBean class and am specifying a hbm.xml file like

    <property name="mappingResources">
    <list>
    <value>com/mycomp/table1.hbm.xml</value>
    <value>com/mycomp/table2.hbm.xml</value>
    </list>
    </property>

    The problem is when I create my context I get the following error

    Could not open class path resource [com/mycomp/table1.hbm.xml]


    This happens because the jar that holds my hbm.xml files is a different jar than the jar that holds the class that is trying to create the context. If I place the hbm.xml files in the same jar it all works. Unfortunatly this is not an option for me. The hiberante files must be in their own jar.

    How do I go about configuring a class loader to find them? Do I have to write my own class loader?

    Any help is appreciated.

    Thanks
    David Noel

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    please try:
    Code:
        <property name="mappingLocations">
          <value>classpath*&#58;com/mycomp/table1.hbm.xml</value>
          <value>classpath*&#58;com/mycomp/table2.hbm.xml</value>
        </property>
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default

    Thanks for the response Omar. Unfortunatly it did not work. I looked at a few of the different setters on the object and none of them seem to work. I thought perhaps the setMappingJarLocations would work but that is not helping either. Are there any examples anywhere that use these methods? Also. I'm a little confused about the classpath* syntax. I have not seen this before. Is this standard Java stuff? Any references so I can read up on it?

    anyway to reiterate my problem....

    jar1.jar contains
    com/mycomp/table1.hbm.xml
    com/mycomp/table2.hbm.xml

    jar2.jar contains
    com/mycomp/mypackage/myclass.class

    myclass creates a FileSystemXMLApplicationContext with a bean def file from the filesystem. Both jar1.jar and jar2.jar are on the classpath. The context can't find the resources in jar1.jar
    David Noel

  4. #4
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default

    bump. I'm still having this problem. Is there anyone out there that has run into this before?
    David Noel

  5. #5

    Default Same thing

    David, I am getting the same error, but my .hbm files aren't in a jar at all. My files are under WEB-INF/classes and it says it can't find them. I am wondering if this has to do with a version of Spring or Hibernate?

  6. #6
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default

    I'm using Spring 1.1.3 with all it's packaged dependencies.
    David Noel

  7. #7
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default

    Well I can write this up as user error This was not a Spring problem. Thanks for the replies though.
    David Noel

  8. #8
    Join Date
    Nov 2004
    Posts
    12

    Default User Error?

    David,

    I hope you get notfied by this post.

    What was the error that was causing this issue?

    I am having similar problems.

    I store the hbm.xml files in one directory path, and have the class files in the other directory.

    I am pretty sure that I am making a silly mistake.

  9. #9
    Join Date
    Jul 2005
    Posts
    110

    Default

    coincidentally, i was just grappling with this last night.

    i have a solution using the mappingJarLocations property which may work for you:

    see: http://forum.springframework.org/showthread.php?t=18701
    Last edited by robyn; May 14th, 2006 at 07:05 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
  •