In my GWT 2.4.0 application I use RequestFactory and Hibernate/JPA. I have an entity Agent
which has many Administrators
through a @OneToMany
relationship. This association is LAZY
loaded. So when the find service is called the administrators of the agent are not loaded which is the desired behaviour in most cases.
However, I want to be able to indicate that I want the administrators of the agent back when firing a requestFactory request on the client side code by using the with method. So my client code would look something like:
RequestContext.findAgent(agentId).with("administrstors").fire()
and My server side service looks something like this:
public Agent findAgent(Long id) {
return getEntityManager().createQuery("SELECT a" +
" FROM Agent" +
" WHERE a.id=:id", Agent.class)
.setParameter("id", id)
.getSingleResult();
}
I want to be able to figure out if the with method was used to sent the request. I need to customize the JPA query to also load the admins of the agent in case with was used on client side. Is there a way to access the details of the request made through the RequestFactory on server side?
If I know that the client code needs the admins of the agent tehn my JPA query would look like :
public Agent findAgent(Long id) {
return getEntityManager().createQuery("SELECT a" +
" FROM Agent a LEFT JOIN a.administrators admin" +
" WHERE a.id=:id", Agent.class)
.setParameter("id", id)
.getSingleResult();
}
Any insight would be appreciated. Thanks in advance.
This is unfortunately impossible; you'll have to pass the information as additional arguments to the method in addition to the with()
.
FYI, that was discussed 2 years ago in a Google Wave (I have a local backup copy, but it's otherwise nowhere to be found on the web), with several proposals (an optional Set<String>
passed as the last argument to the service methods –your findAgent
method–, or a thread-local list of properties).
Nothing like this has been implemented though, and in retrospect I'm not sure it should: passing the information explicitly as arguments to your method is more explicit / has less magic in it.