Vita Rara: A Life Uncommon

Web Page Data Models: Where do they go? Part II

Categories: | |

Well, I finally decided where they go. At least for the Quadran project. My package structure looks like this:

The api package contains all of the interfaces for my domain model objects. The jpa directory contains JPA implementations of my domain objects. The views package contains ad-hoc views of the object models data.

I'm using these views for things like rows in a report that contain a field from this entity, a field from that entity, etc. I'd rather not have to fetch all of the related domain model objects using JPA when I just need a field here or there for display purposes.

Here's an example of using this with a JPA query:

SELECT DISTINCT new (, o.fromPartyOrderNumber,, o.requestedShippingDate, customer.firstName,
    customer.lastName, o.creditApproved, o.toPartyOrderNumber, o.status
FROM Order o 
JOIN o.shipFromAddress sfa 
JOIN sfa.facility f 
JOIN f.facilityArea fa 
JOIN o.toParty customer 
WHERE in ( ? ) 

Having these views allows me to quickly pull data out of the database using JPA and have it in a first class bean, rather than a ResultSet, or an untyped Map.