6 Replies Latest reply on Oct 31, 2007 8:58 AM by terryb

    help with EntityList

    terryb

      With application based on seam-gen, the MyEntityList feature is based on single table. I guess it is possible to make it work with multiple tables. wondering anyone can help me out?

      Table Associations
      Client--->Contacts--->Addresses
      Clients--->Applications

      ---> represents one-to-many

      I get errors like, even though all my search columns are text:
      11:39:16,776 ERROR [DebugPageHandler] redirecting to debug page
      java.lang.NumberFormatException: For input string: "username" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:447)

      Say would like to search by:
      client.username, contact.surname, address.postcode, application.status

      @Name("clientList")
       public class ClientList extends EntityQuery {
      
       private static final String[] RESTRICTIONS = {
       "lower(client.username) like concat('%',lower(#{clientList.client.username}),'%')",
       "lower(contact.surname) like concat('%',lower(#{clientList.contact.surname}),'%')",
       "lower(address.postcode) like concat('%',lower(#{clientList.address.postcode}),'%')",
       "lower(application.status) like concat('%',lower(#{clientList.application.status}),'%')",
       };
      
       private Client client = new Client();
       private Contact contact = new Contact();
       private Address address = new Address();
       pircate Application application = new Application();
      
       @Override
       public String getEjbql() {
      
       return "select client.username, contact.surname, address.postcode, application.status " +
       "from Client client inner join client.contacts contact....????????????????";
       }
      
       public Client getClient() {
       return client;
       }
      
       public Contact getContact() {
       return contact;
       }
      
       public Address getAddress() {
       return address;
       }
      
       public Application getApplication() {
       return application;
       }
      
      ...
      
      }
      


        • 1. Re: help with EntityList
          thejavafreak

          Show us the entity class here.

          • 2. Re: help with EntityList
            terryb

            cut down version of entities involved. I guess I am not sure how to build ejb
            for my case and how to use it in restrictions and eventually how to access it in jsf

            @Entity
             @Table(name = "Client")
            public class Client implements java.io.Serializable {
            
             private String id;
             private String username;
             private Set<Contact> contacts = new HashSet<Contact>(0);
             private Set<Applicant> applicants = new HashSet<Applicant>(0);
            
             public Client() {
             }
            
             .....
            
             @Id
             @Column(name = "ID", unique = true, nullable = false, length = 20)
             @NotNull
             @Length(max = 20)
             public String getId() {
             return this.id;
             }
            
             public void setId(String id) {
             this.id = id;
             }
            
             @Column(name = "Username", length = 20)
             @Length(max = 20)
             public String getUsername() {
             return this.username;
             }
            
             public void setUsername(String username) {
             this.username = username;
             }
            
             @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "client")
             public Set<Contact> getContacts() {
             return this.contacts;
             }
            
             public void setContacts(Set<Contact> contacts) {
             this.contacts = contacts;
             }
             @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "client")
             public Set<Applicant> getApplicants() {
             return this.applicants;
             }
            
             public void setApplicants(Set<Applicant> applicants) {
             this.applicants = applicants;
             }
            
            }
            
            @Entity
             @Table(name = "Contact")
            public class Contact implements java.io.Serializable {
            
             private String id;
             private Client client;
             private String surname;
             private Set<Address> addresses = new HashSet<Address>(0);
            
             @ManyToOne(fetch = FetchType.LAZY)
             @JoinColumn(name = "ClientID")
             public Client getClient() {
             return this.client;
             }
            
             public void setClient(Client client) {
             this.client = client;
             }
            
             @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "contact")
             public Set<Address> getAddresses() {
             return this.addresses;
             }
            
             public void setAddresses(Set<Address> addresses) {
             this.addresses = addresses;
             }
            }
            
            @Entity
             @Table(name = "Address")
            public class Address implements java.io.Serializable {
            
             private String id;
             private Contact contact;
            
             @ManyToOne(fetch = FetchType.LAZY)
             @JoinColumn(name = "ContactID")
             public Contact getContact() {
             return this.contact;
             }
            
             public void setContact(Contact contact) {
             this.contact = contact;
             }
            
            
            }
            
            
            JSF
            ...
            <h:dataTable id="clientList" var="client" value="#{clientList.resultList}" rendered="#{not empty clientList.resultList}" border="1">
            
            <h:column>
            #{client....????}
            </h:column>
            ...
            


            • 3. Re: help with EntityList
              thejavafreak

              Why does your Client and Contact entity does not have any Id?

              • 4. Re: help with EntityList
                terryb

                Hi Joshua, all entities have Id field - I removed extra code to make it less verbose. sorry it caused confusion.

                • 5. Re: help with EntityList
                  pmuir

                  This question is about how to formulate the ejbql? You'll need to ask that on the hibernate jpa forum.

                  • 6. Re: help with EntityList
                    terryb

                    Pete, ejbql formulation is part of it. I am seeking help on how to use a Set of entities (returned in select clause) with seam-gen generated MyEntityList restrictions mechanism; and to use then in h:databTable jsf tag.

                    though I will ask it hibernate forum too, for ebjql help.