Announcement Announcement Module
No announcement yet.
Scanning packages for resources and relative paths Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

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

    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:

    Instead I'm getting this:

    How can I get the relative path instead of the absolute?