Can not create records in the database via Active Objects

Hello

When I try to create a new record in MS Sql database via Active Objects I have an error message in the JIRA log

SQLException: The executeUpdate method must not return a result set.

Why can it happen?
It happens on one MS Sql database
When I try it on another MS Sql databse - everything is ok

Thanks

Can you provide the stack trace where the error is happening as well as the associated code that you’re using to create the record?

Thanks for your response!
Here is the code

package ru.teamlead.jira.plugins.ao.crm.schema;

import net.java.ao.Entity;
import net.java.ao.schema.StringLength;

import java.util.Date;

public interface Tlfieldvalue extends Entity {
String getFieldsetrecordcode();

void setFieldsetrecordcode(String value);


Integer getFieldsetrecordid();

void setFieldsetrecordid(Integer value);


Integer getRecordid();

void setRecordid(Integer value);


String getFieldcode();

void setFieldcode(String value);


String getFieldvalue();

void setFieldvalue(String value);


String getFieldselectvalue();

void setFieldselectvalue(String value);


Boolean getIsname();

void setIsname(Boolean value);


Boolean getIssearch();

void setIssearch(Boolean value);


String getOrderrole();

void setOrderrole(String value);


@StringLength(value = StringLength.MAX_LENGTH)
String getFieldvaluelong();

@StringLength(value = StringLength.MAX_LENGTH)
void setFieldvaluelong(String value);


@StringLength(value = StringLength.MAX_LENGTH)
String getFieldselectvaluelong();

@StringLength(value = StringLength.MAX_LENGTH)
void setFieldselectvaluelong(String value);


Boolean getDefault();

void setDefault(Boolean value);


Date getFieldvaluedate();

void setFieldvaluedate(Date value);


Double getFieldvaluenum();

void setFieldvaluenum(Double value);


Boolean getDisplay();

void setDisplay(Boolean value);


@StringLength(value = StringLength.MAX_LENGTH)
String getFieldvaluelongen();

@StringLength(value = StringLength.MAX_LENGTH)
void setFieldvaluelongen(String value);


@StringLength(value = StringLength.MAX_LENGTH)
String getFieldselectvaluelongen();

@StringLength(value = StringLength.MAX_LENGTH)
void setFieldselectvaluelongen(String value);

}

The call to create new records

protected Tlfieldvalue getFieldValue(
        final Integer recordId,
        final Integer fieldValueId,
        final String val,
        final Tlfieldsetrecord fieldRecord,
        final String tableName,
        final String parentId,
        final String viewVal,
        final JSONObject ret,
        final boolean addDicts,
        final boolean addContact,
        final boolean addProduct,
        final boolean addOrg,
        final String issueId,
        final ApplicationUser user,
        final Audit audit,
        final JSONArray errors
) {
    String viewValue = viewVal;
    String value = val;
    Locale paramLocale = getLocale();

    if ((StringUtils.isNotEmpty(viewValue) && viewValue.length() > 400) ||
            StringUtils.isNotEmpty(value) && value.length() > 400) {
        JSONObject noContactError = new JSONObject();
        try {
            noContactError.put("fieldCode", EDIT_PREFIX + fieldRecord.getFieldcode());
            noContactError.put("errorMessage", i18nBean.getText("teamlead.crm.field.max.size"));
        } catch (JSONException e) {
            log.error(e, e);
        }
        errors.put(noContactError);
    }

    Tlfieldvalue fieldValue;
    if (fieldValueId == null) {

//The problem place!!!
//if no field value - trying to create a new record
fieldValue = ao.create(Tlfieldvalue.class);

        fieldValue.setFieldsetrecordcode(tableName);
        fieldValue.setFieldsetrecordid(fieldRecord.getID());
        fieldValue.setRecordid(recordId);
        fieldValue.save();
    } else {
        fieldValue = ao.get(Tlfieldvalue.class, fieldValueId);
    }

@Override
public Map<String, Object> updateNom(
        final String parentIdVal,
        final String nomId,
        final String tableName,
        final String issueId,
        final String userName,
        final ApplicationUser permUser,
        final Map<String, Object> params,
        final String nojirafieldscheck,
        final Boolean requestFromAPI
) throws CreateException, PermissionException, JSONException {
    final JSONObject ret = new JSONObject();
    final JSONArray cfs = new JSONArray();

    final Integer valueId = parseId(parentIdVal);

    final boolean nojirafieldscheckVal = "true".equals(nojirafieldscheck);

    final Map<String, Object> check = new HashMap<>();
    check.put("updateSla", false);
    check.put("issue", null);

    final Map<String, Object> userInfo = new HashMap<>();
    userInfo.put("create", false);

    final JSONObject result = new JSONObject();

    final Collection<Group> userGroups = groupManager.getGroupsForUser(permUser);
    JSONArray errors = ao.executeInTransaction(new TransactionCallback<JSONArray>() // (1)
    {
        @Override
        public JSONArray doInTransaction() {
            String parentId = parentIdVal;

            if (StringUtils.isEmpty(nomId)) {
                Tlfieldsetrecord[] nameFieldRecords = ao.find(Tlfieldsetrecord.class,
                        Query.select().where(" FIELDSETCODE = ? AND ISNAME = ? ", tableName, true));

                if (nameFieldRecords.length > 0 && !CONTACTS_TABLE_NAME.equals(tableName)) {
                    String name = (String) params.get(EDIT_PREFIX + nameFieldRecords[0].getFieldcode());

                    if (StringUtils.isNotEmpty(name)) {
                        Tlfieldvalue[] nameFieldValues = ao.find(Tlfieldvalue.class,
                                Query.select().where(" FIELDSETRECORDCODE = ? AND ISNAME = ? AND FIELDVALUELONG = ? ",
                                        tableName, true, name));

                        if (nameFieldValues.length > 0) {
                            nom = (Entity) ao.get(classObj, nameFieldValues[0].getRecordid());
                        }
                    }
                }


                if (nom == null) {
                    isNewEntity = true;
                    nom = (Entity) ao.create(classObj);
                    if (nom instanceof ru.teamlead.jira.plugins.ao.crm.Dictionary) {
                        ((ru.teamlead.jira.plugins.ao.crm.Dictionary) nom).setTablename(tableName);
                    }

                    if (!nojirafieldscheckVal) {
                        audit = ao.create(Audit.class);
                        audit.setAuthor(muser.getName());
                        audit.setAuthorName(muser.getDisplayName());
                        audit.setCreated(new Date());
                        audit.setEntity(nom.getID());
                        audit.setEvent(EVENT_CREATE);
                        audit.setEntitytype(tableName);
                        audit.save();
                    }

                    userInfo.put("id", nom.getID());

                    Tlfieldsetrecord[] juFieldRecords = ao.find(Tlfieldsetrecord.class,
                            Query.select().where(" FIELDSETCODE = ? AND FIELDTYPE = ? AND CALCULATED = ? ",
                                    tableName, "jirauser", true));
                    if (juFieldRecords.length > 0) {
                        errors = new JSONArray();

//Call a mehtod to get the field value

                        Tlfieldvalue fieldValue = getFieldValue(
                                nom.getID(),
                                null,
                                "",
                                juFieldRecords[0],
                                tableName,
                                "-10000".equals(parentId) ? "" : parentId,
                                "",
                                ret,
                                addDicts,
                                addContact,
                                addProduct,
                                addOrg,
                                issueId,
                                permUser,
                                audit,
                                errors
                        );

}

And also descriptor

<ao key="ao-module">


ru.teamlead.jira.plugins.ao.crm.schema.Tlfieldvalue

</ao>

<component-import key="ao" name="Active Objects components"
                  interface="com.atlassian.activeobjects.external.ActiveObjects">
    <description>Access to the Active Objects service</description>
</component-import>

Thanks for your response!
Here is the code

2017-07-05 11:49:38,357 http-nio-8080-exec-39 ERROR beiron 709x529962x1 yy3prb 192.168.1.86 /rest/catalog-rest/1.0/catalog/updateNom [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: There was a SQL exception thrown by the Active Objects library:
Database:
- name:Microsoft SQL Server
- version:11.00.2100
- minor version:0
- major version:11
Driver:
- name:jTDS Type 4 JDBC Driver for MS SQL Server and Sybase
- version:1.3.1

java.sql.SQLException: The executeUpdate method must not return a result set.

com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library:
Database:
- name:Microsoft SQL Server
- version:11.00.2100
- minor version:0
- major version:11
Driver:
- name:jTDS Type 4 JDBC Driver for MS SQL Server and Sybase
- version:1.3.1

java.sql.SQLException: The executeUpdate method must not return a result set.
at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.create(EntityManagedActiveObjects.java:94)
at com.atlassian.activeobjects.osgi.TenantAwareActiveObjects.create(TenantAwareActiveObjects.java:266)
… 2 filtered
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy1901.create(Unknown Source)
at ru.teamlead.jira.plugins.crm.CrmUtilsImpl.getFieldValue(CrmUtilsImpl.java:3242)
at ru.teamlead.jira.plugins.crm.CrmUtilsImpl$14.doInTransaction(CrmUtilsImpl.java:4722)
at ru.teamlead.jira.plugins.crm.CrmUtilsImpl$14.doInTransaction(CrmUtilsImpl.java:4385)
at com.atlassian.sal.core.transaction.HostContextTransactionTemplate$1.doInTransaction(HostContextTransactionTemplate.java:21)
at com.atlassian.jira.DefaultHostContextAccessor.doInTransaction(DefaultHostContextAccessor.java:34)
… 2 filtered
at java.lang.reflect.Method.invoke(Method.java:498)

In fact in the database table there are records created - with only ID
Other fields are empty
And we have the error in the log
May be there is some problem with the table structure?
It is for MS SQL 2012
It works for MySQL, Postgres etc
Also it seems to work with test instance with MS SQL 2017
And it used to work with MS SQL 2012 two weeks ago((

Hi Volodgel,
Have you tried to create the entity with the parameter?.
Example:

DBParam[] parameter = {
      new DBParam("tableName-ColumnName", tableName),
      new DBParam("FieldRecord-ColumnName", fieldRecord.getID()),
      new DBParam("Record-ColumnName", recordId)};

this.ao.create(Tlfieldvalue.class, parameter);