0 Replies Latest reply on Dec 9, 2005 4:05 PM by Michael Small

    org.hibernate.PropertyAccessException: IllegalArgumentExcept

    Michael Small Newbie

      I'm struggling to solve the error I've been receiving. In overview, I have two types of people in the system, Provider and Clients. A Provider can have many ProviderContacts and a Client can have many ClientContacts. When I attempt to load a Client (which has a mapped collection to ClientContacts), I get an error.

      This is the query I'm running:

      SELECT c
      FROM Client c
      WHERE c.relationship.relationshipId LIKE :expression OR
       c.taxId LIKE :expression OR
       c.clientName LIKE :expression
      


      This is the error I receive ...
      14:41:37,846 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.tasconline.client.ClientContact, setter method of property: client
      14:41:37,846 ERROR [BasicPropertyAccessor] expected type: com.tasconline.client.Client, actual value: com.tasconline.provider.Provider
      14:41:37,846 INFO [DefaultLoadEventListener] Error performing load command
      org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.tasconline.client.ClientContact.client
       at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
       at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:330)
       at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:188)
       at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3231)
       at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
       at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
       at org.hibernate.loader.Loader.doQuery(Loader.java:717)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
      
      


      This is the Client entity:
      @Entity
      @Table(name="tasc_client")
      @Inheritance(strategy=InheritanceType.JOINED,
       discriminatorValue="Client")
      @PrimaryKeyJoinColumn(name="fk_tasc_relationship_binding")
      public class Client extends RelationshipBinding {
      
       private static final String BINDING_TYPE = "Client";
      
       private TaxId taxId;
       private TaxFilingStatus taxFilingStatus;
       private OrganizationName clientName;
       private Address shippingAddress;
       private Address billingAddress;
       private Collection<ClientContact> contacts;
      
       /**
       *
       */
       public Client() {
       this.bindingType = BINDING_TYPE;
       this.contacts = new LinkedList<ClientContact>();
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverride(name="id", column=@Column(name="taxId"))
       public TaxId getTaxId() {
       return(this.taxId);
       }
      
       /**
       *
       */
       public void setTaxId(TaxId taxId) {
       this.taxId = taxId;
       }
      
       /**
       *
       */
       @Transient
       public TaxFilingStatus getTaxFilingStatus() {
       return(this.taxFilingStatus);
       }
      
       /**
       *
       */
       @Transient
       public void setTaxFilingStatus(TaxFilingStatus taxFilingStatus) {
       this.taxFilingStatus = taxFilingStatus;
       }
      
       /**
       *
       */
       @Column(name="taxFilingStatus")
       public String getTaxFilingStatusType(String taxFilingStatusType) {
       if (this.taxFilingStatus == null) return(null);
       return(this.taxFilingStatus.name());
       }
      
       /**
       *
       */
       public void setTaxFilingStatusType(String taxFilingStatusType) {
       if (taxFilingStatusType == null) {
       this.taxFilingStatus = null;
       return;
       } else {
       for (TaxFilingStatus status: TaxFilingStatus.values()) {
       if (status.name().equals(taxFilingStatusType)) {
       this.taxFilingStatus = status;
       return;
       }
       }
       throw new IllegalArgumentException
       ("Invalid TaxFilingStatus: " + taxFilingStatusType);
       }
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverride(name="name", column=@Column(name="clientName"))
       public OrganizationName getClientName() {
       return(this.clientName);
       }
      
       /**
       *
       */
       public void setClientName(OrganizationName clientName) {
       this.clientName = clientName;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverrides({
       @AttributeOverride(name="address1", column=@Column(name="shippingAddress1")),
       @AttributeOverride(name="address2", column=@Column(name="shippingAddress2")),
       @AttributeOverride(name="city", column=@Column(name="shippingCity")),
       @AttributeOverride(name="stateAbbreviation", column=@Column(name="shippingState")),
       @AttributeOverride(name="deliveryArea", column=@Column(name="shippingDeliveryArea")),
       @AttributeOverride(name="plusFour", column=@Column(name="shippingPlusFour"))
       })
       public Address getShippingAddress() {
       return(this.shippingAddress);
       }
      
       /**
       *
       */
       public void setShippingAddress(Address shippingAddress) {
       this.shippingAddress = shippingAddress;
       }
      
       /**
       *
       */
       @AttributeOverrides({
       @AttributeOverride(name="address1", column=@Column(name="billingAddress1")),
       @AttributeOverride(name="address2", column=@Column(name="billingAddress2")),
       @AttributeOverride(name="city", column=@Column(name="billingCity")),
       @AttributeOverride(name="stateAbbreviation", column=@Column(name="billingState")),
       @AttributeOverride(name="deliveryArea", column=@Column(name="billingDeliveryArea")),
       @AttributeOverride(name="plusFour", column=@Column(name="billingPlusFour"))
       })
       public Address getBillingAddress() {
       return(this.billingAddress);
       }
      
       /**
       *
       */
       public void setBillingAddress(Address billingAddress) {
       this.billingAddress = billingAddress;
       }
      
       /**
       *
       */
       @OneToMany(
       mappedBy="client",
       fetch=FetchType.EAGER,
       cascade=CascadeType.ALL)
       public Collection<ClientContact> getContacts() {
       return(this.contacts);
       }
      
       /**
       *
       */
       public void setContacts(Collection<ClientContact> contacts) {
       this.contacts = contacts;
       }
      
       /**
       *
       */
       @Transient
       public Contact getPrimaryContact() {
      
       // see if there is a primary
       for (ClientContact contact: this.contacts) {
       if (contact.isPrimary()) {
       return(contact);
       }
       }
      
       // no primary
       return(null);
      
       }
      


      This is the ClientContact entity:
      @Entity
      @Table(name="tasc_client_contact")
      @Inheritance
      public class ClientContact extends ValueObject
       implements Contact, Comparable<Contact> {
      
       private Client client;
       private Boolean primary;
       private PersonName name;
       private PhoneNumber homeNumber;
       private PhoneNumber businessNumber;
       private PhoneNumber faxNumber;
       private PhoneNumber mobileNumber;
       private EmailAddress emailAddress;
       private Address address;
      
       /**
       *
       */
       @ManyToOne(targetEntity=com.tasconline.client.Client.class,
       fetch=FetchType.EAGER)
       @JoinColumn(name="fk_tasc_client")
       public Client getClient() {
       return(this.client);
       }
      
       /**
       *
       */
       public void setClient(Client client) {
       this.client = client;
       }
      
       /**
       *
       */
       @Column(name="primaryContact")
       public Boolean isPrimary() {
       return(this.primary);
       }
      
       /**
       *
       */
       public void setPrimary(Boolean primary) {
       this.primary = primary;
       }
      
       /**
       *
       */
       @Embedded
       public PersonName getName()
       {
       return(this.name);
       }
      
       /**
       *
       */
       public void setName(PersonName name)
       {
       this.name = name;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverrides({
       @AttributeOverride(name="areaCode", column=@Column(name="homeNumberAreaCode")),
       @AttributeOverride(name="trunk", column=@Column(name="homeNumberTrunk")),
       @AttributeOverride(name="number", column=@Column(name="homeNumberNumber")),
       @AttributeOverride(name="extension",column=@Column(name="homeNumberExtension"))
       })
       public PhoneNumber getHomeNumber()
       {
       return(this.homeNumber);
       }
      
       /**
       *
       */
       public void setHomeNumber(PhoneNumber homeNumber)
       {
       this.homeNumber = homeNumber;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverrides({
       @AttributeOverride(name="areaCode", column=@Column(name="businessNumberAreaCode")),
       @AttributeOverride(name="trunk", column=@Column(name="businessNumberTrunk")),
       @AttributeOverride(name="number", column=@Column(name="businessNumberNumber")),
       @AttributeOverride(name="extension",column=@Column(name="businessNumberExtension"))
       })
       public PhoneNumber getBusinessNumber()
       {
       return(this.businessNumber);
       }
      
       /**
       *
       */
       public void setBusinessNumber(PhoneNumber businessNumber)
       {
       this.businessNumber = businessNumber;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverrides({
       @AttributeOverride(name="areaCode", column=@Column(name="faxNumberAreaCode")),
       @AttributeOverride(name="trunk", column=@Column(name="faxNumberTrunk")),
       @AttributeOverride(name="number", column=@Column(name="faxNumberNumber")),
       @AttributeOverride(name="extension",column=@Column(name="faxNumberExtension"))
       })
       public PhoneNumber getFaxNumber()
       {
       return(this.faxNumber);
       }
      
       /**
       *
       */
       public void setFaxNumber(PhoneNumber faxNumber)
       {
       this.faxNumber = faxNumber;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverrides({
       @AttributeOverride(name="areaCode", column=@Column(name="mobileNumberAreaCode")),
       @AttributeOverride(name="trunk", column=@Column(name="mobileNumberTrunk")),
       @AttributeOverride(name="number", column=@Column(name="mobileNumberNumber")),
       @AttributeOverride(name="extension",column=@Column(name="mobileNumberExtension"))
       })
       public PhoneNumber getMobileNumber()
       {
       return(this.mobileNumber);
       }
      
       /**
       *
       */
       public void setMobileNumber(PhoneNumber mobileNumber)
       {
       this.mobileNumber = mobileNumber;
       }
      
       /**
       *
       */
       @Embedded
       @AttributeOverride(name="address", column=@Column(name="emailAddress"))
       public EmailAddress getEmailAddress()
       {
       return(this.emailAddress);
       }
      
       /**
       *
       */
       public void setEmailAddress(EmailAddress emailAddress)
       {
       this.emailAddress = emailAddress;
       }
      
       /**
       *
       */
       @Embedded
       public Address getAddress() {
       return(this.address);
       }
      
       /**
       *
       */
       public void setAddress(Address address) {
       this.address = address;
       }
      
      }