• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Master Detail table mapping

 
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a master table people and detail places. In my DAO, I query for all people and I can easily use a Class implementing RowMapper to map each row .

Is there a way to also get the list of places for each person while i am getting each person without having to reiterate through the list after i get the list of people?
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can join the 2 tables in a SQL, and sort them by People's ID. Define a "PeoplePlaces" class that contains the columns from both tables, and in your RowMapper, return the PeoplePlaces object. In your DAO method, the queryForObject method will return a list of PeoplePlaces objects that will be sorted by peopleId. You can then iimplement an algorithm that iterates over the PeoplePlaces and seperates the People from the Places

OR

You can use an ORM layer like JPA/Hibernate, and the ORM layer will do all this work for you. You don;t have to reinvent the wheel.
 
Michelle Nicholes
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a performance hit to use JPA, hibernate?
Prior to learning Spring, I was using EJBs and I was using JPA with the EJBs.
but I was told the huge websites which performance is an issue, they used Spring which is why I am now learning Spring.
So, with that said, which one of your suggestions do the high performance sites use?
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With JPA, it's all about how you design the ORM layer. If you put a lot of eager one to many mappings, performance will suffer. You need to look at the raw sqls thT hibernate runs to optimize your entity mapping
 
reply
    Bookmark Topic Watch Topic
  • New Topic