Announcement Announcement Module
Collapse
No announcement yet.
Scanning packages for resources and relative paths Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scanning packages for resources and relative paths

    I've got a Hibernate + JPA application. We started out with JPA annotations, but recently fell back to Hibernate hbm files for various reasons - the entities are less cluttered and mapping complex relationships is easier. Hibernate lets you pass hbm files to the JPA Entity Manager, so all is well.

    However, the LocalContainerEntityManagerFactoryBean only lets you pass a String array for mapping files. This means I have to manually create and maintain a gigantic <util:list> of mapping files (I've got 150+ entities, huge database). The old Hibernate Session Factory was able to scan the classpath and find mapping files automatically.

    I'm attempting to write a bean to scan the classpath for certain resources and return them in a String array so it can be passed into the JPA Entity Manager:

    Code:
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource [] resources = resolver.getResources("classpath*:my/package/**/*.hbm.xml");
    I've also tried this:

    Code:
    context.getResources("classpath*:my/package/**/*.xml");
    The array returned is a bunch of absolute path file:// URLs, when what I really want is a relative URL. What am I doing wrong?

    This is what I'm looking to ultimately create:

    Code:
    /my/package/one.hbm.xml
    /my/package/two.hbm.xml
    Instead I'm getting this:

    Code:
    file:/C:/eclipse/.../my/package/one.hbm.xml
    How can I get the relative path instead of the absolute?
Working...
X