Adding party relationship roles - error message is confusing.
-------------------------------------------------------------
Key: OFBIZ-3406
URL: https://issues.apache.org/jira/browse/OFBIZ-3406
Project: OFBiz
Issue Type: Bug
Components: party
Affects Versions: SVN trunk
Reporter: chris snow
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:
{code}
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.)))
{code}
If validation code was put into the createPartyRelationship service, a more
friendly error message could be returned to the user:
{code}
<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 "to role" of '${parameters.roleTypeIdTo}', but party ID
${parameters.partyIdFrom} 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 "from role" 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>
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.