OFBiz
  1. OFBiz
  2. OFBIZ-3406

Adding party relationship roles - error message is confusing.

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Trunk
    • Fix Version/s: None
    • Component/s: party
    • Labels:
      None

      Description

      On a few occasions I have tried to add party relationships, but have failed with an error message similar to the following. The error message provided no help in identifying the problem:

      Error trying to begin transaction, could not process method: The current transaction is marked for rollback, not beginning a new transaction and aborting 
      current operation; the rollbackOnly was caused by: Failure in create operation for entity [PartyRole]: org.ofbiz.entity.GenericEntityException: Error while 
      inserting: [GenericEntity:PartyRole][createdStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][createdTxStamp,2010-01-11 
      14:04:01.966(java.sql.Timestamp)][lastUpdatedStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][lastUpdatedTxStamp,2010-01-11 
      14:04:01.966(java.sql.Timestamp)][partyId,100001(java.lang.String)][roleTypeId,_NA_(java.lang.String)] (SQL Exception while executing the 
      following:INSERT INTO OFBIZ.PARTY_ROLE (PARTY_ID, ROLE_TYPE_ID, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, 
      CREATED_TX_STAMP) VALUES (?, ?, ?, ?, ?, ?) (INSERT on table 'PARTY_ROLE' caused a violation of foreign key constraint 'PARTY_RLE_PARTY' for 
      key (100001). The statement has been rolled back.)). Rolling back transaction.org.ofbiz.entity.GenericEntityException: Error while inserting: 
      [GenericEntity:PartyRole][createdStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][createdTxStamp,2010-01-11 14:04:01.966(java.sql.Timestamp)]
      [lastUpdatedStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][lastUpdatedTxStamp,2010-01-11 14:04:01.966(java.sql.Timestamp)]
      [partyId,100001(java.lang.String)][roleTypeId,_NA_(java.lang.String)] (SQL Exception while executing the following:INSERT INTO OFBIZ.PARTY_ROLE 
      (PARTY_ID, ROLE_TYPE_ID, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP) VALUES (?, ?, ?, ?, 
      ?, ?) (INSERT on table 'PARTY_ROLE' caused a violation of foreign key constraint 'PARTY_RLE_PARTY' for key (100001). The statement has been rolled 
      back.)) (Error while inserting: [GenericEntity:PartyRole][createdStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][createdTxStamp,2010-01-11 
      14:04:01.966(java.sql.Timestamp)][lastUpdatedStamp,2010-01-11 14:04:02.002(java.sql.Timestamp)][lastUpdatedTxStamp,2010-01-11 
      14:04:01.966(java.sql.Timestamp)][partyId,100001(java.lang.String)][roleTypeId,_NA_(java.lang.String)] (SQL Exception while executing the 
      following:INSERT INTO OFBIZ.PARTY_ROLE (PARTY_ID, ROLE_TYPE_ID, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, 
      CREATED_TX_STAMP) VALUES (?, ?, ?, ?, ?, ?) (INSERT on table 'PARTY_ROLE' caused a violation of foreign key constraint 'PARTY_RLE_PARTY' for 
      key (100001). The statement has been rolled back.)))
      

      If validation code was put into the createPartyRelationship service, a more friendly error message could be returned to the user:

          <simple-method method-name="createPartyRelationship" short-description="createPartyRelationship">
              <if-empty field="parameters.roleTypeIdFrom"><set field="parameters.roleTypeIdFrom" value="_NA_"/></if-empty>
              <if-empty field="parameters.roleTypeIdTo"><set field="parameters.roleTypeIdTo" value="_NA_"/></if-empty>
              <if-empty field="parameters.partyIdFrom"><set field="parameters.partyIdFrom" from-field="userLogin.partyId"/></if-empty>
      
              <if-empty field="parameters.fromDate"><now-timestamp field="parameters.fromDate"/></if-empty>
      
              <!-- check if not already exist -->
              <entity-and entity-name="PartyRelationship" list="partyRels" filter-by-date="true">
                  <field-map field-name="partyIdFrom" from-field="parameters.partyIdFrom"/>
                  <field-map field-name="roleTypeIdFrom" from-field="parameters.roleTypeIdFrom"/>
                  <field-map field-name="partyIdTo" from-field="parameters.partyIdTo"/>
                  <field-map field-name="roleTypeIdTo" from-field="parameters.roleTypeIdTo"/>
              </entity-and>
      
      <!-- MORE HELPFUL ERROR MESSAGE START -->
      		<if-compare field="parameters.roleTypeIdTo" operator="not-equals" value="_NA_">
      			<entity-one entity-name="PartyRole" value-field="lookedUpToPartyRole">
      				<field-map field-name="partyId" from-field="parameters.partyIdTo"/>
      				<field-map field-name="roleTypeId" from-field="parameters.roleTypeIdTo"/>
      			</entity-one>
      			<if-empty field="lookedUpToPartyRole">
      				<!-- TODO : read this message from a resource file -->
      				<set field="failMessage" value="You have tried to assign a &quot;to role&quot; of '${parameters.roleTypeIdTo}', but party ID ${parameters.partyIdTo} does not have a '${parameters.roleTypeIdTo}' role.  "/>
      				<string-append field="failMessage" string="Use the Role(s) screen for party ID ${parameters.partyIdTo} to first assign the '${parameters.roleTypeIdTo}' role to them."/>
      				<add-error><fail-message message="${failMessage}"/></add-error>
      			</if-empty>
      		</if-compare>
      
      		<if-compare field="parameters.roleTypeIdFrom" operator="not-equals" value="_NA_">
      			<entity-one entity-name="PartyRole" value-field="lookedUpFromPartyRole">
      				<field-map field-name="partyId" from-field="parameters.partyIdFrom"/>
      				<field-map field-name="roleTypeId" from-field="parameters.roleTypeIdFrom"/>
      			</entity-one>
      			<if-empty field="lookedUpFromPartyRole">
      				<!-- TODO : read this message from a resource file -->
      				<set field="failMessage" value="You have tried to assign a &quot;from role&quot; of '${parameters.roleTypeIdFrom}', but party ID ${parameters.partyIdFrom} does not have a '${parameters.roleTypeIdFrom}' role.  "/>
      				<string-append field="failMessage" string="Use the Role(s) screen for party ID ${parameters.partyIdFrom} to first assign the '${parameters.roleTypeIdFrom}' role to them."/>
      				<add-error><fail-message message="${failMessage}"/></add-error>
      			</if-empty>
      		</if-compare>
      		<check-errors/>
      <!-- MORE HELPFUL ERROR MESSAGE END-->
      
              <if-empty field="partyRels">
                  <make-value value-field="newEntity" entity-name="PartyRelationship"/>
                  <set-pk-fields map="parameters" value-field="newEntity"/>
                  <set-nonpk-fields map="parameters" value-field="newEntity"/>
                  <create-value value-field="newEntity"/>
              </if-empty>
          </simple-method>
      

        Activity

        Hide
        David E. Jones added a comment -

        This is probably best discussed on the dev mailing list, and in fact there was a recent discussion related to this about automatically adding users to roles in a relationship instead of returning any sort of error message.

        Show
        David E. Jones added a comment - This is probably best discussed on the dev mailing list, and in fact there was a recent discussion related to this about automatically adding users to roles in a relationship instead of returning any sort of error message.
        Hide
        Jacques Le Roux added a comment -

        Here it is, but I have no time yet to seriously do the work I will do for sure one day, maturing...

        Show
        Jacques Le Roux added a comment - Here it is , but I have no time yet to seriously do the work I will do for sure one day, maturing...
        Hide
        BJ Freeman added a comment -

        There are two ECAS that make sure the to and from Relationships have NA for roles if null.
        can this be closed.

        Show
        BJ Freeman added a comment - There are two ECAS that make sure the to and from Relationships have NA for roles if null. can this be closed.
        Hide
        Jacques Le Roux added a comment -

        BJ,

        Nope, only if the desired roleTypeIdFrom or roleTypeIdTo is NA...

        Show
        Jacques Le Roux added a comment - BJ, Nope, only if the desired roleTypeIdFrom or roleTypeIdTo is NA ...
        Hide
        BJ Freeman added a comment -

        Ok, seems that once the PartyRelationshipType is specified that the PartyRelationshipType.roleTypeIdValidFrom and PartyRelationshipType.roleTypeIdValidto can be done with a EECA
        Then the only Screen that is available is the PartyRelationshipType

        Show
        BJ Freeman added a comment - Ok, seems that once the PartyRelationshipType is specified that the PartyRelationshipType.roleTypeIdValidFrom and PartyRelationshipType.roleTypeIdValidto can be done with a EECA Then the only Screen that is available is the PartyRelationshipType

          People

          • Assignee:
            Jacques Le Roux
            Reporter:
            chris snow
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development