views:

255

answers:

1

I've been working with Seam and JPA/Hibernate for quite some time, but have just started looking at making use of the EntityHome and EntityQuery classes more. EntityHome seems relatively straightforward in terms of what it is and how I can leverage it. But, EntityQuery is a bit less clear.

I understand the ability to grab, for example, a list containing all of a given entity. However, I've also seen some examples using a RESTRICTIONS array. How exactly is this used? Are the OR conditions or AND conditions? Can anyone give me some more detailed information as to how EntityQuery is intended to be used? I've checked the few books I have on Seam and JPA, but none of them really reference the EntityQuery classes. It seems like I very useful mechanism, and I'd like to get some more use out of them if I can. Thanks!

+1  A: 

First of all, I would like to say that from a professional point of view, that you should stay away from the Seam Entity/Query/Home framework.

You can read my comment on why you shouldn't use it here

If you however want to use it, you must know it is a trade off you are taking. It will make things go slower, however it is easier to use.

That said, let me try to answer your questions with some examples:

However, I've also seen some examples using a RESTRICTIONS array. How exactly is this used? Are the OR conditions or AND conditions?

Since Seam 2.2.0 (if I am not mistaken) you have the option to add RESTRICTIONS with OR/AND. You can set this with the restrictionLogicOperator operator in your view like this:

<ui:define name="label">Match</ui:define>
<h:selectOneRadio id="logic" value="#{myEnityQueryList.restrictionLogicOperator}" styleClass="radio">
  <f:selectItem itemLabel="AND" itemValue="and"/>
  <f:selectItem itemLabel="OR" itemValue="or"/>
</h:selectOneRadio>

This code should be a part of a form that is mapped against your EntityQuery object together with some RESTRICTIONS. The restrictions are used to filter the query so you can retrieve the correct resultset. For instance:

private static final String[] RESTRICTIONS = { "lower(person.name) like lower(concat(#{personList.person.name},'%'))"}

So if you have a name field in your form, you can type John and it and it will add John% to the query.

Can anyone give me some more detailed information as to how EntityQuery is intended to be used?

The EntityQuery is intended to be used together with some search form. You bind your form against the fields you want to search for, and then it will retrieve a list based on the result as I described above.

Shervin