Results 1 to 7 of 7

Thread: lazy loading of mapping files

  1. #1

    Default lazy loading of mapping files

    Hi,
    I am using spring in the combination of hibernate. I have a lot of mapping files(*.hbm.xml) that is configured at the in the applicationContext.xml
    Everything is working fine. Since all these files are loading at the startup it's consuming a lot of memory. In the development environment this is affecting very badly.
    I want these files to be loaded only on demand except at the startup. How do i acheive this

    Thanks,
    Parimala

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    You can't. The mapping files have to be loaded at startup so that Hibernate can properly create the SessionFactory - if the files are not loaded and parsed the SessionFactory is invalid. In fact, if one wants to add another mapping file, it has to destroy the existing factory and create a new one.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    Thanks for the reply....

    Since there are lot files all the mapping related things are loading at the startup, this is causing the major problem in the development. how do i atleast minimize this

    regards

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I don't really see how you can do much about this. If you have lots of mapped objects you have to load the mappings.

    What are the underlying problems you are trying to solve? Is it just startup time and memory consumption.
    Last edited by karldmoore; Nov 15th, 2006 at 05:22 AM.

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Yup, there isn't much you can do about it - it's a mandatory cost which you have to pay upfront. There were some discussions about serializing the SessionFactory but that's fragile and unsupported out of the box. All you can save, is parsing the XML file by using cacheableResourceMappings which will parse the XML once and then simply verify if it's the same file and if it, reuse the definition.
    In my experience this didn't improve performance noticeable but I assume for applications with plenty of mapping files - such as yours, it might eliminate some of the performance overhead.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote Originally Posted by sudha_parimala View Post
    Thanks for the reply....

    Since there are lot files all the mapping related things are loading at the startup, this is causing the major problem in the development. how do i atleast minimize this

    regards
    It is rather Hibernate then Spring problem. BTW, may be it worth a try to look for some alternative to Hibernate?

  7. #7
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default

    Hey Parimala,

    This may be more trouble than it's worth, but if you are testing component A, which relies only on persistent objects P1 and P2, then that component could have it's own context file with a LocalSessionFactory declaration including only the P1 and P2 mapping files. (This of course assumes that P1 and P2 do not have references to other persistent classes).
    Arthur Loder
    Software Engineer
    Fancast
    Comcast Interactive Media

Posting Permissions

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