Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] How to disable resolving of IndirectList on detached entities?

Hi,

I have a question that follows another question I recently asked on StackOverflow, here: http://stackoverflow.com/questions/30163294/how-to-avoid-loading-lazy-bidirectional-relationships-with-moxy.

Here's a summary: I'm mixing JPA and JAXB/MOXy annotations on a single class. The entities are exposed through a JAX-RS method. If there is a bidirectional relationship, I use @XmlInverseReference, which avoids cycle exceptions when the objects are marshalled. But in order to detect the cycle, MOXy (apparently/obviously) has to inspect the relationship from the other end too. If that field is lazily loaded, I would like to prevent EclipseLink from running additional SQL SELECTs, as I already have all the data that needs to be marshalled. What happens though is that when the JAX-RS method returns, the automatic JAXB marshalling does trigger an SQL SELECT even though my entity is already detached. So the IndirectList field is still resolved at this point. From what I could gather (e.g. here: http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg07254.html), this behaviour must be due to the default non-transactional read connection pool that EclipseLink uses.

Since I wasn't aware of that default read connection pool, it is possible that other parts of my application might break if I was to disable it. However, I think that's not so likely; in fact I've already relied on the fact that the entities are detached in my JAX-RS methods to apply some presentation-layer only modifications to them. I'd rather make sure that all my lazy relationships are loaded in the service layer before the entities are detached, IF I'd lose some information that was formerly present in the marshalled data.

My question is: what is a recommended way to prevent those additional SQL queries? Apart from the fact that lazy relationships would need to be taken more care of before entities are detached, would there be any other disadvantage if I just disabled that read connection pool? Is that even possible, and if so how could that be achieved? Or are there more elegant solutions? (note - like I mentioned in the SO question, I can't even just null out the backreference to suppress the SQL queries, presumably because the woven proxy intercepts this?)


Thanks in advance and best regards,
Joachim Kanbach


Back to the top