Frustrations with enityquery multi-entity properties query
nmatrix9 Nov 2, 2009 4:32 AM*Sigh*
After my previous battles with EntityQuery with my book "Seam In Action". I thought I had EnityQuery figured out but unfortunately the javax.servlet.ServletException says other wise. I've re-read chapter 10 of Seam in Action to try and emulate the description on Page 458 "the hierarchial example object that can be fed into the join query . . ". Not so hard right? Well This is what I did for my components.xml just like in Seam in Action.
...
<component class="com.domain.exoshellcms.entity.ExoshellUsers" name="userExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellRoles" name="roleExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellModules" name="moduleExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellUserRoles"
name="userRolesExample" scope="CONVERSATION">
<property name="exoshellUsers">#{userExample}</property>
<property name="exoshellRoles">#{roleExample}</property>
<property name="exoshellModules>#{moduleExample}</property>
</component>
...
the entity relationship I believe is similar to what the round -> golfer, round -> teeset relationship is like in the book Seam in action. For my particular case it is:
ExoshellUsers ExoshellRoles ExoshellModules 0 to 1 entities
\ | /
\ | /
\ | /
ExoshellUserRoles 0 to 1-n entity
+ userRolesId
+ ExoshellUsers
+ ExoshellRoles
+ ExoshellModules
It seems that no matter what, the entity exoshellUserRoles cannot access it's entity properties exoshellUsers etc. Even if I do a eager fetch in a entity query. Any insight as to what I'm missing or overlooking would be greatly appreciated.
and my supporting session bean:
@Name("exoshellUserRolesList")
@Scope(ScopeType.SESSION)
public class ExoshellUserRolesList extends EntityQuery<ExoshellUserRoles> {
/* UNABLE TO GET RESTRICTIONS TO WORK WITHOUT POINTING TO NULL PARENT OBJECT I.E. exoshellUsers, exoshellRoles or exoshellModules */
private static final String[] RESTRICTIONS = {
"lower(exoshellUserRoles.exoshellUsers.username) like concat(lower(#{userRolesExample.exoshellUsers.username}),'%')"
};
private ExoshellUserRoles exoshellUserRoles = new ExoshellUserRoles();
private String queryString = new String("select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles inner join fetch exoshellUserRoles.exoshellUsers exoshellUsers");
public ExoshellUserRolesList() {
setEjbql(queryString);
}
@Override
public String getEjbql() {
return queryString;
}
public ExoshellUserRoles getExoshellUserRoles() {
return exoshellUserRoles;
}
@Override
public List<String> getRestrictions() {
return Arrays.asList(RESTRICTIONS);
}
@Override
public String getOrder() {
return new String("exoshellUserRoles.exoshellUsers.username asc");
}
}
The corresponding interface frontend:
....
<h:inputText id="userRoleName" value="#{userRolesExample.exoshellUsers.username}">
....
inputing a username for entityquery search throws the following error:
21:54:48,942 ERROR [ExceptionFilter] exception root cause
javax.el.PropertyNotFoundException: /admin/ExoshellUserRolesEdit.xhtml @339,99 value="#{userRolesExample.exoshellUsers.username}": Target Unreachable, identifier 'userRolesExample' resolved to null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92) . . .
For EL expressions and entity query I've also tried:
1. exoshellUserRolesList.exoshellUsers.username
"select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles join fetch exoshellUserRoles.exoshellUsers exoshellUsers"
with error:
Exception during request processing:
Caused by javax.servlet.ServletException with message: "/admin/ExoshellUserRolesEdit.xhtml @339,122 value="#{exoshellUserRolesList.exoshellUserRoles.exoshellUsers.username}": Target Unreachable, 'exoshellUsers' returned null on 'com.domain.exoshellcms.entity.ExoshellUserRoles'"
After my previous battles with EntityQuery with my book "Seam In Action". I thought I had EnityQuery figured out but unfortunately the javax.servlet.ServletException says other wise. I've re-read chapter 10 of Seam in Action to try and emulate the description on Page 458 "the hierarchial example object that can be fed into the join query . . ". Not so hard right? Well This is what I did for my components.xml just like in Seam in Action.
...
<component class="com.domain.exoshellcms.entity.ExoshellUsers" name="userExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellRoles" name="roleExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellModules" name="moduleExample"/>
<component class="com.domain.exoshellcms.entity.ExoshellUserRoles"
name="userRolesExample" scope="CONVERSATION">
<property name="exoshellUsers">#{userExample}</property>
<property name="exoshellRoles">#{roleExample}</property>
<property name="exoshellModules>#{moduleExample}</property>
</component>
...
the entity relationship I believe is similar to what the round -> golfer, round -> teeset relationship is like in the book Seam in action. For my particular case it is:
ExoshellUsers ExoshellRoles ExoshellModules 0 to 1 entities
\ | /
\ | /
\ | /
ExoshellUserRoles 0 to 1-n entity
+ userRolesId
+ ExoshellUsers
+ ExoshellRoles
+ ExoshellModules
It seems that no matter what, the entity exoshellUserRoles cannot access it's entity properties exoshellUsers etc. Even if I do a eager fetch in a entity query. Any insight as to what I'm missing or overlooking would be greatly appreciated.
and my supporting session bean:
@Name("exoshellUserRolesList")
@Scope(ScopeType.SESSION)
public class ExoshellUserRolesList extends EntityQuery<ExoshellUserRoles> {
/* UNABLE TO GET RESTRICTIONS TO WORK WITHOUT POINTING TO NULL PARENT OBJECT I.E. exoshellUsers, exoshellRoles or exoshellModules */
private static final String[] RESTRICTIONS = {
"lower(exoshellUserRoles.exoshellUsers.username) like concat(lower(#{userRolesExample.exoshellUsers.username}),'%')"
};
private ExoshellUserRoles exoshellUserRoles = new ExoshellUserRoles();
private String queryString = new String("select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles inner join fetch exoshellUserRoles.exoshellUsers exoshellUsers");
public ExoshellUserRolesList() {
setEjbql(queryString);
}
@Override
public String getEjbql() {
return queryString;
}
public ExoshellUserRoles getExoshellUserRoles() {
return exoshellUserRoles;
}
@Override
public List<String> getRestrictions() {
return Arrays.asList(RESTRICTIONS);
}
@Override
public String getOrder() {
return new String("exoshellUserRoles.exoshellUsers.username asc");
}
}
The corresponding interface frontend:
....
<h:inputText id="userRoleName" value="#{userRolesExample.exoshellUsers.username}">
....
inputing a username for entityquery search throws the following error:
21:54:48,942 ERROR [ExceptionFilter] exception root cause
javax.el.PropertyNotFoundException: /admin/ExoshellUserRolesEdit.xhtml @339,99 value="#{userRolesExample.exoshellUsers.username}": Target Unreachable, identifier 'userRolesExample' resolved to null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92) . . .
For EL expressions and entity query I've also tried:
1. exoshellUserRolesList.exoshellUsers.username
"select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles join fetch exoshellUserRoles.exoshellUsers exoshellUsers"
with error:
Exception during request processing:
Caused by javax.servlet.ServletException with message: "/admin/ExoshellUserRolesEdit.xhtml @339,122 value="#{exoshellUserRolesList.exoshellUserRoles.exoshellUsers.username}": Target Unreachable, 'exoshellUsers' returned null on 'com.domain.exoshellcms.entity.ExoshellUserRoles'"