aspose file tools*
The moose likes Struts and the fly likes Struts2 and XML subnodes to show database relationships? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 and XML subnodes to show database relationships?" Watch "Struts2 and XML subnodes to show database relationships?" New topic
Author

Struts2 and XML subnodes to show database relationships?

J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 28
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!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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.


[How To Ask Questions On JavaRanch]
J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 28
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 and XML subnodes to show database relationships?