The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Lazy fetching useless with SOAP?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 3 - Last Post: Oct 12, 2006 2:00 PM by: sbalmos
sbalmos

Posts: 56
Lazy fetching useless with SOAP?
Posted: Oct 11, 2006 8:17 PM
  Click to reply to this thread Reply

Hi all,

This is more of an architectural question... Apparently lazy fetching of an entity's relationships and collections is completely useless with SOAP, because the JAXB XML marshaller touches each of the entity's properties, and thus causing a lazy fetch.

I was somewhat hoping that entities with lazy-fetching properties or collections would, somehow, just return the entity IDs of the entity / collection member entities. I have other explicit methods for retrieving those other member entities, given entity IDs.

But since every property is touched, it's like everything is eagerly fetched. This can *easily* get out of control in my envisioned system, where hundreds of collection members can have parents that have hundreds of other members, etc etc etc. The classic parent/child tree problem which lazy fetching was supposed to solve.

I'm wondering if anyone has any idea on how to rearchitect this. :/

Thanks!

--Scott

chris_delahunt

Posts: 153
Re: Lazy fetching useless with SOAP?
Posted: Oct 12, 2006 8:52 AM   in response to: sbalmos
  Click to reply to this thread Reply

Hello Scott,

Not sure why the marshaller is touching everything, but two ways out I can see are:
1)Use property based access. This will prevent accessing the attributes directly from causing them to load.

2)The other solution would be to not map relationships at all. Instead, you can map foreign keys as basic mappings, and use these values to lookup the referenced entity.

Best Regards,
Chris

robdaemon

Posts: 4
Re: Lazy fetching useless with SOAP?
Posted: Oct 12, 2006 10:14 AM   in response to: sbalmos
  Click to reply to this thread Reply

I've handled this by creating a business facade for my SOAP calls that all return a set of DTO's that aren't my full entities. I wrote a class to map the entities to the DTO's, and then I marshall the DTO's back to the client.

The app I had designed this way had a web-based front end and a thick client. The thick client used the special facade with limited DTO's (it had a totally different set of functionality than the web UI) and the web UI relied on my standard facade and entity beans.

Hope this helps,

Rob

sbalmos

Posts: 56
Re: Lazy fetching useless with SOAP?
Posted: Oct 12, 2006 2:00 PM   in response to: robdaemon
  Click to reply to this thread Reply

Hi Rob,

That was my first thought, painful as it was. However, I just got this solved with Kohsuke (from the JAXB realm) over in the JAXB forum.

http://forums.java.net/jive/thread.jspa?messageID=162557&#162557

See his blog entry on XML attribute pairs. These work like a charm directly in the entities themselves. I'll post up some quick sample code when I get home from work later today.

This works if you're like me, where you have entities (or collections of such) as return values, but entity *IDs* or collections of such (not entities themselves) as incoming method parameters. If you did that, I guess you could have some logic in the setter that turns around to your DAO layer and... well... looks itself up from the persistence engine? That seems like an entity / DAO abstraction violation in the making.

Anyway... See if that might help you also.

--Scott




 XML java.net RSS