2 Replies Latest reply on Oct 26, 2009 9:22 AM by wolfgangknauf

    SessionBean and the case of RESTRICTIONS for entitquery

    nmatrix9

      Hello EJB 3.0 Users

      I've just noticed that creates class that extends EntityQuery, some generated classes do NOT have any restrictsion set in the RESTRICTIONS array. I tried to find out why but so far I have not found any useful information on this. Anyways I have a class called ExoshellUsersRolesList that extends EntityQuery (originally generated by Seam-Gen) to which it did not have it's RESTRICTIONS array set. So I decided I would manually set the array myself like so.

      package com.domain.exoshellcms.session;

      import com.domain.exoshellcms.entity.*;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.framework.EntityQuery;
      import java.util.List;
      import java.util.Arrays;

      @Name("exoshellUserRolesList")
      @Scope(ScopeType.SESSION)
      public class ExoshellUserRolesList extends EntityQuery {
      /* UNABLE TO GET RESTRICTIONS TO WORK WITHOUT POINTING TO NULL PARENT OBJECT I.E. exoshellUsers, exoshellRoles or exoshellModules */
      private static final String[] RESTRICTIONS = {
      "lower(users.username) like concat(lower(#{exoshellUserRolesList.exoshellUserRoles.exoshellUsers.username}),'%')",
      "lower(exoshellUserRoles.exoshellRoles.roleName) like concat(lower(#{exoshellUserRolesList.exoshellUserRoles.exoshellRoles.roleName}),'%')",
      "lower(exoshellUserRoles.exoshellModules.moduleName) like concat(lower(#{exoshellUserRolesList.exoshellUserRoles.exoshellModules.moduleName}),'%')"
      };

      private ExoshellUserRoles exoshellUserRoles = new ExoshellUserRoles();
      private String queryString = new String("select exoshellUserRoles, users from ExoshellUserRoles exoshellUserRoles join fetch exoshellUserRoles.exoshellUsers users");
      @Override
      public String getEjbql() {
      return queryString;
      }

      public ExoshellUserRoles getExoshellUserRoles() {
      return exoshellUserRoles;
      }

      @Override
      public List getRestrictions() {
      return Arrays.asList(RESTRICTIONS);
      }

      @Override
      public String getOrder() {
      return new String("exoshellUserRoles.userRolesId asc");
      }
      }



      I then created a corresponding interface form to search through a datable using the ExoshellUsersList like so:

      <rich:simpleTogglePanel label="User Roles search parameters" switchType="ajax" opened="false" ignoreDupResponses="true" eventsQueue="userSearchQueue" requestDelay="2000" immediate="true" rendered="false">

      <s:decorate template="/layout/display.xhtml">
      <ui:define name="label">User Name</ui:define>
      <h:inputText id="userRoleName" value="#{exoshellUserRolesList.exoshellUserRoles.exoshellUsers.username}">
      <a:support event="onblur" reRender="panelusers,userRolesPaginator" ignoreDupResponses="true"/>
      </h:inputText>
      </s:decorate>

      <s:decorate template="/layout/display.xhtml">
      <ui:define name="label">Role Name</ui:define>
      <h:inputText id="userRoleRolename" value="#{exoshellUserRolesList.exoshellUserRoles.exoshellRoles.roleName}">
      <a:support event="onblur"/>
      </h:inputText>
      </s:decorate>

      <s:decorate template="/layout/display.xhtml">
      <ui:define name="label">Module</ui:define>
      <h:inputText id="userRoleModule" value="#{exoshellUserRolesList.exoshellUserRoles.exoshellModules.moduleName}">
      <a:support event="onblur"/>
      </h:inputText>
      </s:decorate>

      </rich:simpleTogglePanel>

      Unfortunately this was not enough as when I try to input text into one of the search fields (like User Name) upon ajax update I get the 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'"


      Any insight, documentation or solutions to the exception above would be greatly appreciated. I've include the relied upon EJB entities below after this post.

        • 1. Re: SessionBean and the case of RESTRICTIONS for entitquery
          nmatrix9

          @Entity
          @Name("users")
          @Table(name = "exoshell_users", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = {
          "username", "emailaddress" }))
          public class ExoshellUsers implements java.io.Serializable {

          private int userId;
          private String username;
          private String userpassword;
          private String firstname;
          private String lastname;
          private String emailaddress;
          private String userimage;
          private byte[] picture;
          private Date registered;
          private String gender;
          private Date lastLogin;
          private String ipAddress;
          private boolean accountenabled;
          private Set exoshellUserRoleses = new HashSet(
          0);
          public ExoshellUsers() {
          }

          public ExoshellUsers(String username, String userpassword,
          String firstname, String lastname, String emailaddress,
          Date registered, String gender, Date lastLogin, String ipAddress,
          boolean accountenabled) {
          this.username = username;
          this.userpassword = userpassword;
          this.firstname = firstname;
          this.lastname = lastname;
          this.emailaddress = emailaddress;
          this.registered = registered;
          this.gender = gender;
          this.lastLogin = lastLogin;
          this.ipAddress = ipAddress;
          this.accountenabled = accountenabled;
          }

          public ExoshellUsers(String username, String userpassword,
          String firstname, String lastname, String emailaddress,
          String userimage, Date registered, String gender, Date lastLogin,
          String ipAddress, boolean accountenabled,
          Set exoshellUserRoleses) {
          this.username = username;
          this.userpassword = userpassword;
          this.firstname = firstname;
          this.lastname = lastname;
          this.emailaddress = emailaddress;
          this.userimage = userimage;
          this.registered = registered;
          this.gender = gender;
          this.lastLogin = lastLogin;
          this.ipAddress = ipAddress;
          this.accountenabled = accountenabled;
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          @Id
          @GeneratedValue(strategy=GenerationType.AUTO)
          @Column(name = "user_id", unique = true, nullable = false)
          @NotNull
          public int getUserId() {
          return this.userId;
          }

          public void setUserId(int userId) {
          this.userId = userId;
          }

          @Column(name = "username", nullable = false, length = 20)
          @NotNull
          @Length(max = 20)
          public String getUsername() {
          return this.username;
          }

          public void setUsername(String username) {
          this.username = username;
          }

          @Column(name = "userpassword", nullable = false, length = 40)
          @NotNull
          @Length(max = 40)
          public String getUserpassword() {
          return this.userpassword;
          }

          public void setUserpassword(String userpassword) {
          this.userpassword = userpassword;
          }

          @Column(name = "firstname", nullable = false, length = 40)
          @NotNull
          @Length(max = 40)
          public String getFirstname() {
          return this.firstname;
          }

          public void setFirstname(String firstname) {
          this.firstname = firstname;
          }

          @Column(name = "lastname", nullable = false, length = 40)
          @NotNull
          @Length(max = 40)
          public String getLastname() {
          return this.lastname;
          }

          public void setLastname(String lastname) {
          this.lastname = lastname;
          }

          @Column(name = "emailaddress", nullable = false)
          @NotNull
          @Email(message="Input is not a valid email")
          public String getEmailaddress() {
          return this.emailaddress;
          }

          public void setEmailaddress(String emailaddress) {
          this.emailaddress = emailaddress;
          }

          @Column(name = "userimage")
          public String getUserimage() {
          return this.userimage;
          }

          public void setUserimage(String userimage) {
          this.userimage = userimage;
          }

          @Temporal(TemporalType.DATE)
          @Column(name = "registered", nullable = false, length = 13)
          @NotNull
          public Date getRegistered() {
          return this.registered;
          }

          public void setRegistered(Date registered) {
          this.registered = registered;
          }

          @Column(name = "gender", nullable = false, length = 6)
          @NotNull
          @Length(max = 6)
          public String getGender() {
          return this.gender;
          }

          public void setGender(String gender) {
          this.gender = gender;
          }

          @Temporal(TemporalType.TIMESTAMP)
          @Column(name = "last_login", nullable = false, length = 29)
          @NotNull
          public Date getLastLogin() {
          return this.lastLogin;
          }

          public void setLastLogin(Date lastLogin) {
          this.lastLogin = lastLogin;
          }

          @Column(name = "ip_address", nullable = false, length = 32)
          @NotNull
          @Length(max = 32)
          public String getIpAddress() {
          return this.ipAddress;
          }

          public void setIpAddress(String ipAddress) {
          this.ipAddress = ipAddress;
          }

          @Column(name = "accountenabled", nullable = false)
          @NotNull
          public boolean isAccountenabled() {
          return this.accountenabled;
          }

          public void setAccountenabled(boolean accountenabled) {
          this.accountenabled = accountenabled;
          }

          @OneToMany(fetch = FetchType.LAZY, mappedBy = "exoshellUsers", cascade = {CascadeType.ALL})
          public Set getExoshellUserRoleses() {
          return this.exoshellUserRoleses;
          }

          public void setExoshellUserRoleses(
          Set exoshellUserRoleses) {
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          public byte[] getPicture() {
          return picture;
          }

          public void setPicture(byte[] picture) {
          this.picture = picture;
          }
          }


          @Entity
          @Name("roles")
          @Table(name = "exoshell_roles", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = "role_name"))
          public class ExoshellRoles implements java.io.Serializable {

          private int roleId;
          private String roleName;
          private Set exoshellUserRoleses = new HashSet(
          0);

          public ExoshellRoles() {
          }

          public ExoshellRoles(String roleName) {
          this.roleName = roleName;
          }

          public ExoshellRoles(String roleName,
          Set exoshellUserRoleses) {
          this.roleName = roleName;
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          @Id
          @GeneratedValue(strategy=GenerationType.AUTO)
          @Column(name = "role_id", unique = true, nullable = false)
          @NotNull
          public int getRoleId() {
          return this.roleId;
          }

          public void setRoleId(int roleId) {
          this.roleId = roleId;
          }

          @Column(name = "role_name", unique = true, nullable = false, length = 30)
          @NotNull
          @Length(max = 30)
          public String getRoleName() {
          return this.roleName;
          }

          public void setRoleName(String roleName) {
          this.roleName = roleName;
          }

          @OneToMany(fetch = FetchType.LAZY, mappedBy = "exoshellRoles", cascade = {CascadeType.ALL})
          public Set getExoshellUserRoleses() {
          return this.exoshellUserRoleses;
          }

          public void setExoshellUserRoleses(
          Set exoshellUserRoleses) {
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          }

          @Entity
          @Name("modules")
          @Table(name = "exoshell_modules", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = "module_name"))
          public class ExoshellModules implements java.io.Serializable {

          private int moduleId;
          private ExoshellModuleCategories exoshellModuleCategories;
          private String moduleName;
          private boolean moduleStatus;
          private String moduleImage;
          private Date moduleInstalled;
          private String username;
          private String ipAddress;
          private Set exoshellModContentManagerCategorieses = new HashSet(
          0);
          private Set exoshellUserRoleses = new HashSet(
          0);

          public ExoshellModules() {
          }

          public ExoshellModules(
          ExoshellModuleCategories exoshellModuleCategories,
          String moduleName, boolean moduleStatus, String moduleImage,
          Date moduleInstalled, String username, String ipAddress) {
          this.exoshellModuleCategories = exoshellModuleCategories;
          this.moduleName = moduleName;
          this.moduleStatus = moduleStatus;
          this.moduleImage = moduleImage;
          this.moduleInstalled = moduleInstalled;
          this.username = username;
          this.ipAddress = ipAddress;
          }

          public ExoshellModules(
          ExoshellModuleCategories exoshellModuleCategories,
          String moduleName,
          boolean moduleStatus,
          String moduleImage,
          Date moduleInstalled,
          String username,
          String ipAddress,
          Set exoshellModContentManagerCategorieses,
          Set exoshellUserRoleses) {
          this.exoshellModuleCategories = exoshellModuleCategories;
          this.moduleName = moduleName;
          this.moduleStatus = moduleStatus;
          this.moduleImage = moduleImage;
          this.moduleInstalled = moduleInstalled;
          this.username = username;
          this.ipAddress = ipAddress;
          this.exoshellModContentManagerCategorieses = exoshellModContentManagerCategorieses;
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          @Id
          @GeneratedValue(strategy=GenerationType.AUTO)
          @Column(name = "module_id", unique = true, nullable = false)
          @NotNull
          public int getModuleId() {
          return this.moduleId;
          }

          public void setModuleId(int moduleId) {
          this.moduleId = moduleId;
          }

          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "module_category_id", nullable = false)
          @NotNull
          public ExoshellModuleCategories getExoshellModuleCategories() {
          return this.exoshellModuleCategories;
          }

          public void setExoshellModuleCategories(
          ExoshellModuleCategories exoshellModuleCategories) {
          this.exoshellModuleCategories = exoshellModuleCategories;
          }

          @Column(name = "module_name", unique = true, nullable = false, length = 40)
          @NotNull
          @Length(max = 40)
          public String getModuleName() {
          return this.moduleName;
          }

          public void setModuleName(String moduleName) {
          this.moduleName = moduleName;
          }

          @Column(name = "module_status", nullable = false)
          @NotNull
          public boolean isModuleStatus() {
          return this.moduleStatus;
          }

          public void setModuleStatus(boolean moduleStatus) {
          this.moduleStatus = moduleStatus;
          }

          @Column(name = "module_image", nullable = false)
          @NotNull
          public String getModuleImage() {
          return this.moduleImage;
          }

          public void setModuleImage(String moduleImage) {
          this.moduleImage = moduleImage;
          }

          @Temporal(TemporalType.DATE)
          @Column(name = "module_installed", nullable = false, length = 13)
          @NotNull
          public Date getModuleInstalled() {
          return this.moduleInstalled;
          }

          public void setModuleInstalled(Date moduleInstalled) {
          this.moduleInstalled = moduleInstalled;
          }

          @Column(name = "username", nullable = false, length = 20)
          @NotNull
          @Length(max = 20)
          public String getUsername() {
          return this.username;
          }

          public void setUsername(String username) {
          this.username = username;
          }

          @Column(name = "ip_address", nullable = false, length = 32)
          @NotNull
          @Length(max = 32)
          public String getIpAddress() {
          return this.ipAddress;
          }

          public void setIpAddress(String ipAddress) {
          this.ipAddress = ipAddress;
          }

          @OneToMany(fetch = FetchType.LAZY, mappedBy = "exoshellModules")
          public Set getExoshellModContentManagerCategorieses() {
          return this.exoshellModContentManagerCategorieses;
          }

          public void setExoshellModContentManagerCategorieses(
          Set exoshellModContentManagerCategorieses) {
          this.exoshellModContentManagerCategorieses = exoshellModContentManagerCategorieses;
          }

          @OneToMany(fetch = FetchType.LAZY, mappedBy = "exoshellModules", cascade = {CascadeType.ALL})
          public Set getExoshellUserRoleses() {
          return this.exoshellUserRoleses;
          }

          public void setExoshellUserRoleses(
          Set exoshellUserRoleses) {
          this.exoshellUserRoleses = exoshellUserRoleses;
          }

          }

          @Entity
          @Name("userRoles")
          @Table(name = "exoshell_user_roles", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = {
          "module_id", "user_id", "role_id" }))
          public class ExoshellUserRoles implements java.io.Serializable {

          private int userRolesId;
          private ExoshellUsers exoshellUsers;
          private ExoshellRoles exoshellRoles;
          private ExoshellModules exoshellModules;
          private Set exoshellImageses = new HashSet(
          0);
          private ExoshellUserRolesRules exoshellUserRolesRuleses;
          public ExoshellUserRoles() {
          }

          public ExoshellUserRoles(int userRolesId, ExoshellUsers exoshellUsers,
          ExoshellRoles exoshellRoles) {
          this.userRolesId = userRolesId;
          this.exoshellUsers = exoshellUsers;
          this.exoshellRoles = exoshellRoles;
          }

          public ExoshellUserRoles(int userRolesId, ExoshellUsers exoshellUsers,
          ExoshellRoles exoshellRoles, ExoshellModules exoshellModules,
          Set exoshellImageses,
          ExoshellUserRolesRules exoshellUserRolesRuleses) {
          this.userRolesId = userRolesId;
          this.exoshellUsers = exoshellUsers;
          this.exoshellRoles = exoshellRoles;
          this.exoshellModules = exoshellModules;
          this.exoshellImageses = exoshellImageses;
          this.exoshellUserRolesRuleses = exoshellUserRolesRuleses;
          }

          @Id
          @GeneratedValue(strategy=GenerationType.AUTO)
          @Column(name = "user_roles_id", unique = true, nullable = false)
          @NotNull
          public int getUserRolesId() {
          return this.userRolesId;
          }

          public void setUserRolesId(int userRolesId) {
          this.userRolesId = userRolesId;
          }

          @ManyToOne(fetch = FetchType.EAGER)
          @JoinColumn(name = "user_id", nullable = false)
          @NotNull
          public ExoshellUsers getExoshellUsers() {
          return this.exoshellUsers;
          }

          public void setExoshellUsers(ExoshellUsers exoshellUsers) {
          this.exoshellUsers = exoshellUsers;
          }

          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "role_id", nullable = false)
          @NotNull
          public ExoshellRoles getExoshellRoles() {
          return this.exoshellRoles;
          }

          public void setExoshellRoles(ExoshellRoles exoshellRoles) {
          this.exoshellRoles = exoshellRoles;
          }

          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "module_id", nullable = true)
          public ExoshellModules getExoshellModules() {
          return this.exoshellModules;
          }

          public void setExoshellModules(ExoshellModules exoshellModules) {
          this.exoshellModules = exoshellModules;
          }

          @OneToMany(fetch = FetchType.LAZY, mappedBy = "exoshellUserRoles")
          public Set getExoshellImageses() {
          return exoshellImageses;
          }

          public void setExoshellImageses(Set exoshellImageses) {
          this.exoshellImageses = exoshellImageses;
          }

          @OneToOne(fetch = FetchType.LAZY, mappedBy = "exoshellUserRoles", cascade={CascadeType.ALL})
          public ExoshellUserRolesRules getExoshellUserRolesRuleses() {
          return exoshellUserRolesRuleses;
          }

          public void setExoshellUserRolesRuleses(
          ExoshellUserRolesRules exoshellUserRolesRuleses) {
          this.exoshellUserRolesRuleses = exoshellUserRolesRuleses;
          }
          }

          • 2. Re: SessionBean and the case of RESTRICTIONS for entitquery
            wolfgangknauf

            Hi,

            better post this in the SEAM forum: http://www.seamframework.org/Community/Forums

            Best regards

            Wolfgang