• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mapping 2 versions of a POJO: POJO and POJOAggr

 
Clark Butler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a simple, real-world case that I cannot find documented anywhere in HBM.

I have a POJO which also contains a Set of dependent objects. For performance, I would like to have 2 ways of accessing - the POJO with and without the Set. The POJO version is for list results, then the POJO + Set version is for details of a single instance.

Normally I would represent these objects as a POJO and its Aggregate, like so (please imagine getters/setters for brevity):



I cannot figure out how to model this in Hibernate.
  • If I map 2 separate objects to the same table, when I query for a List of search results, HBM calculates results for both objects (Result and ResultAggr), even though I am matching the proper class name in the query.

  • The HBM inheritance examples cover polymorphism very well, but does not cover a case as (seemingly) simple as this.



  • I think I am going to have to manage the sub-list entirely independently. But then I will lose the cascading and many-to-many abilities of HBM for the Aggregated case, which I don't want to do.

    I very much appreciate any ideas. If it means anything, I'm using HBM3 via Spring's template wrappers.
     
    Clark Butler
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I should post my current Aggregated HBM descriptor:



    And so if I try to add



    HBM maps both, always.

    But since there is no required discriminator, the only difference between the types being aggregation of dependent data, I can not find an inheritence-based HBM pattern that will implement this persistence.

    Thanks again -
     
    Jeff Albertson
    Ranch Hand
    Posts: 1780
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have you tried the following, which sounds like the simplest approach?

    1. Have one POJO class with a Set-valued property.
    2. Map the set lazily (the default in Hibernate 3.0):

    In your code, these dependent object will only be selected from the database if you attempt to access them or ask Hibernate to explicitly initialize them.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic