BackendlessException{ code: '8001', message: 'Duplicate property: Value1' }

I’d like to use BeforeCreate in Business logic.
But it isn’t possible to use by an error (BackendlessException {code: ‘8001’, message: ‘Duplicate property: Value1’}).

Nothing is being processed in BeforeCreate.

What is a problem?


//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


package com.sample.models;


import com.backendless.Backendless;
import java.util.Date;


public class Work {
    private String Value1;
    private Date updated;
    private String objectId;
    private String ownerId;
    private Date created;


    public Work() {
    }


    public String getValue1() {
        return this.Value1;
    }


    public Date getUpdated() {
        return this.updated;
    }


    public String getObjectId() {
        return this.objectId;
    }


    public String getOwnerId() {
        return this.ownerId;
    }


    public Date getCreated() {
        return this.created;
    }


    public void setValue1(String Value1) {
        this.Value1 = Value1;
    }


    public void setUpdated(Date updated) {
        this.updated = updated;
    }


    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }


    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }


    public void setCreated(Date created) {
        this.created = created;
    }


    public Work save() {
        return (Work)Backendless.Data.of(Work.class).save(this);
    }


    public Long remove() {
        return Backendless.Data.of(Work.class).remove(this);
    }


    public static Work findById(String id) {
        return (Work)Backendless.Data.of(Work.class).findById(id);
    }


    public static Work findFirst() {
        return (Work)Backendless.Data.of(Work.class).findFirst();
    }


    public static Work findLast() {
        return (Work)Backendless.Data.of(Work.class).findLast();
    }
}

package com.sample.events.persistence_service;

import com.backendless.BackendlessCollection;
import com.backendless.geo.GeoPoint;
import com.backendless.persistence.BackendlessDataQuery;
import com.backendless.property.ObjectProperty;
import com.backendless.servercode.ExecutionResult;
import com.backendless.servercode.RunnerContext;
import com.backendless.servercode.annotation.Asset;
import com.backendless.servercode.annotation.Async;

import com.sample.models.Work;

import java.util.HashMap;
import java.util.Map;

/**
 * WorkTableEventHandler handles events for all entities. This is accomplished
 * with the @Asset( "Work" ) annotation.
 * The methods in the class correspond to the events selected in Backendless
 * Console.
 */

@Asset( "Work" )
public class WorkTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<Work>
{

  @Override
  public void afterCreate( RunnerContext context, Work work, ExecutionResult<Work> result ) throws Exception
  {
    // add your code here
  }

  @Override
  public void beforeCreate( RunnerContext context, Work work) throws Exception
  {
    // add your code here
  }

}
  

Hi kunito

Looks like you are using “Unique Constraint” for the column, see attached screenshot

Regards, Vlad

Hi Vladimir

I’m not using “Unique Constraint”. A screen shot is attached.
When not using “BeforeCreate”, it isn’t a problem.

Thanks

Hi llya

I’ll attach a source full set.
app id: DEE3CABA-4B38-1BD5-FF7F-DBEE7C8FE600

Thanks

MyApplication.zip (784.94kB)

Hi kunito,

Please provide us your app id and an example of code how you create a new object in table “Work”.

Regards, Ilya

Hi llya

It isn’t possible to preserve a character string of “Surrogates Pair”.
Therefore if “Surrogates Pair” is included in a character string, I’d like to eliminate.
I’d like to do that in BeforeCreate.

Thanks

Hi, kunito.
I have tried to reproduce your problem. I created table Work with “String Value1” and in event handler “beforeCreate” analyzed the string value before save. All works fine for me.
Try to do this on clear app with one table and one event handler.