• 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

Struts2 and XML subnodes to show database relationships?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I posted a similar question about the same issue in the Hibernate forum but want to see what Struts programmers think.

My issue is this: I have a database table, say "Persons," that has a one-to-many relationship with other tables, say "PhoneNumbers" and "Emails" what I am trying to do (and what I thought using Hibernate and Struts2 together would accomplish) is to be able to generate XML over HTTP output in which the entries are nested, something like this:




There does not seem to be an easy way to do this in Struts2 beyond running separate "PhoneNumber" and "Email" queries against the database for every single person and then loading the results into Lists, Hashmaps or the like after each query, what seems like a very slow, bloated and inefficient way to do things if we are talking about a database with hundreds of thousands of people. In order to find a more elegant solution I tried using Hibernate in conjunction with Struts2; Hibernate automatically built my DAO classes, and it uses Set objects to hold the "PhoneNumbers" and "Email" objects that are related to a particular "Persons" instance. However, it seems that the Struts2 XSLT result type cannot handle these Set objects; I merely get an unhandled exception when the xml is being transformed, whereas the result works fine if I remove the Set objects.

So, what is the easiest/best/most preferred way to build more complex XML output in Struts2


Thanks!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

J Ellis wrote:
I posted a similar question about the same issue in the Hibernate forum but want to see what Struts programmers think.



I've locked your other post to keep the conversation in one place.

J Ellis wrote:
There does not seem to be an easy way to do this in Struts2 beyond running separate "PhoneNumber" and "Email" queries against the database for every single person and then loading the results into Lists, Hashmaps or the like after each query, what seems like a very slow, bloated and inefficient way to do things if we are talking about a database with hundreds of thousands of people.



There is nothing in Struts that prevents you from using a more efficient algorithm for producing your result set, and why would you be loading hundreds of thousands of records onto a page anyway?
Hibernate is not magic, it is simply an ORM, and will probably be every bit as inefficient as manual SQL in this case. You just wouldn't see the ugly in your code.

J Ellis wrote:
Hibernate automatically built my DAO classes



You can manually create classes and manually map them in Hibernate. Unfortunately, I've never used the Struts2 XSLT result type, so I can't tell you what would play nice.
 
J Ellis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe,

Thank you for the information! I think I will go the route that you mentioned, give up using the XSLT result type, and create my own result set using DOM objects. The nature of the application dictates that I load hundreds of thousands of records all at once; all of the entries are displayed in a spreadsheet-like format that allows a user to view them, to sort them, and to quickly add or change information.

Thanks again,

Justin
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic