Results 1 to 2 of 2

Thread: [HHH] Support for Config.addClas() in Hibernate 3

  1. #1
    Join Date
    Oct 2004
    Location
    Salvador, BA, Brazil
    Posts
    5

    Default [HHH] Support for Config.addClas() in Hibernate 3

    Hibernate 3 Config class has a nifty way to find out mapping files based on class names; call Config.addClas(Class clazz) and it will look for a mapping file on the same directory as that clazz, suffixed by ".hbm.xml".

    So, what I'd love to see in spring is:

    Code:
    <bean id="sessionFactory" class="LocalSessionFactoryBean">
      <property name="mappingClasses">
        <list>
            <value>br.com.mycompany.myproject.MyObject</value>
            <value>br.com.mycompany.myproject.MyChild</value>
        </list>
      </property>
    </bean>
    You could argue that "mappingResources" is almost the same, except that you use "/" instead of ".", and you have to explicitely add the ".hbm.xml" suffix. That would be true, if I didn't use IDEA for my day-to-day programming. When I move or rename a class in IDEA, it will not only properly refactor the references in java code, but will also figure out references to the fully qualified class name in non-java (let's say, our lovely application context) and rename them.

    If you use IDEA, you know what I'm talking about, and feel my pain. If you don't, you have no idea (no pun intended) how useful this little feature would be.

    EDIT: for removing duplicate words words.

  2. #2
    Join Date
    Oct 2004
    Location
    Salvador, BA, Brazil
    Posts
    5

    Default Alternative solution

    As a side note, I'm currently circumventing this problem by subclassing LocalSessionFactoryBean to add a "mappingClasses" property that delegates to the "mappingResources" property:

    Code:
    public class ClassAwareLocalSessionFactoryBean extends LocalSessionFactoryBean
    &#123;
        public void setMappingClasses&#40;Class&#91;&#93; mappingClasses&#41;
        &#123;
            String&#91;&#93; mappingResources = new String&#91;mappingClasses.length&#93;;
    
            for &#40;int i = 0; i < mappingClasses.length; i++&#41;
                mappingResources&#91;i&#93; = mappingClasses&#91;i&#93;.getName&#40;&#41;.replace&#40;'.', '/'&#41; + ".hbm.xml";
    
            setMappingResources&#40;mappingResources&#41;;
        &#125;
    &#125;
    This works, but it would be nicer if instead of manually translating the class name to a mapping file, LocalSessionFactoryBean actually acknowledged a collection of classes to pass to Config.addClass(), and let Hibernate figure out the resource locations.

Similar Threads

  1. Replies: 2
    Last Post: Sep 7th, 2005, 07:10 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 5
    Last Post: Jun 16th, 2005, 03:35 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Problem using Hibernate Support and JSF
    By jagarciaga in forum Data
    Replies: 9
    Last Post: Sep 29th, 2004, 02:04 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
  •