Some Relations to objects remove automatically

Hello Backendless Team,
We have “auctions” column in users table and I make its relationship with another table named “auctions” many time we noticed that its relation is loose automatically, How is it possible ?? Please check and help me out of this.
Also we observed this type of bug in other tables relations. relationship type (one to many)

My Application name is Poze and App ID Is : C3B46A6B-6793-4561-9033-3845A19EC182
Please check as soon as possible

The only way a relationship can disappear is when the logic in your program removes it. You should check all the logic and identify the place where it happens.

Regards,
Mark

Hi @mark-piller ,
We use this code to add and update auctions in table, Please check
Is there anything wrong in my code.

      if(auctionId){
        newAuction["objectId"] = auctionId;
        
        const auctionInsertResult = uow.update("Auctions",newAuction);
		      const eventTypeCouplingResult = uow.setRelation(auctionInsertResult, "event_type", [eventTypeId]);
	        	const charityCouplingResult = uow.setRelation(auctionInsertResult, "charity", [charityId]);
		     // const charityCouplingResult = uow.setRelation(auctionInsertResult, "charities", [charityId]);
		      const userCouplingResult = uow.setRelation("Users", ownerUserId, "auctions", auctionInsertResult);
          
  			return await uow.execute()
  				.then(async(uowResult) =>{
            await Backendless.Data.of("Users").save(update)
  					return uowResult;
  				});
    }else{

        const auctionInsertResult = uow.create("Auctions",newAuction);
        const eventTypeCouplingResult = uow.addToRelation(auctionInsertResult, "event_type", [eventTypeId]);
        const charityCouplingResult = uow.addToRelation(auctionInsertResult, "charity", [charityId]);
        // const charityCouplingResult = uow.addToRelation(auctionInsertResult, "charities", [charityId]);
        const userCouplingResult = uow.addToRelation("Users", ownerUserId, "auctions", auctionInsertResult);
        
          return await uow.execute()
          .then(async(uowResult) =>{
              await Backendless.Data.of("Users").save(update)
              return uowResult;
          });
    }

Hi, @Ayaz_Khan

Please, make sure that addToRelation operation adds child objects to a parent in a relationship. Unlike setRelation removes any existing child objects and sets the provided children. I think that may be the reason.
Also, it is not clear from your code exactly what does the line?

await Backendless.Data.of('Users').save(update)

Regards,
Marina

Hi @Marina.Kan,

At one place I removed the setRelation() code as I do not need to update child objects anymore,
But in one place in my code where users place bids on auctions. we use this code Please check

      const uow = new Backendless.UnitOfWork();
      //uow.setIsolationLevel( Backendless.UnitOfWork.IsolationLevelEnum.SERIALIZABLE );
      Backendless.Data.of('Auctions').save({objectId: auction_objectId, num_bids: 
      auctionSimple[0].num_bids + 1})
	
      const bid = new Bids();
      bid["bid_amount"] = bid_amount;
      const bidInsertResult = uow.create(bid);
      const auctionCouplingResult = uow.addToRelation(bidInsertResult, "auction", [auction_objectId]);
      const bidderCouplingResult = uow.addToRelation(bidInsertResult, "bidder", [userObjectId]);

this code many times work properly but sometimes it makes the relation of bids table with Users but failed to make relation with auctions table. don’t know why. Any suggestion?

Hello @Ayaz_Khan,

do you receive any errors when transaction fails to make relation with auctions table?
If so could you please provide those errors?

Regards,
Olha

Hi @olhadanylova,

I am using API in my react-native app and at times when relation fails, I did not notice any error or any uncommon behaviour in my app.

Please see screenShot of my Bids Table
many time relations create but sometimes it fails.

Hello @Ayaz_Khan

I assume it happens because you do not wait until a new Auctions is created, try to add await

await Backendless.Data.of('Auctions').save({objectId: auction_objectId, num_bids: 
      auctionSimple[0].num_bids + 1})
	
...
await uow.execute()

Ok, I will try this.

@Ayaz_Khan

I’d also like to clarify about

I did not notice any error

The uowResult contains information about errors.
If transaction operation fails the uowResult.success = false and error will contain the informative message about the problem, but application won’t crash.
Please check this documentation for more information.

Regards,
Olha

1 Like

Hi @vladimir-upirov,

I added await before every database operation but still, sometimes Relation is not created. Please see the screenshot.

You should debug your code. Check for any exceptions. If a relation is not created, the reason would be described in the error that is returned.

Hi @mark-piller,
I get backendless error msg when one of our users tries to put build on an auction. Please check if it will help to resolve the issue.

   {"message":"Backendless encountered an error while handling the request. An internal trouble ticket with ID 81D4076F-3ED1-E2AC-FFFD-F08B2DEB2600 has been created and we will be investigating the issue.\nFor input string: \"text\"\njava.lang.NumberFormatException: For input string: \"text\"\n\tat java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\n\tat java.base/java.lang.Integer.parseInt(Integer.java:652)\n\tat java.base/java.lang.Integer.parseInt(Integer.java:770)\n\tat com.backendless.services.persistence.common.Entity.addModifiedFromString(Entity.java:404)\n\tat com.backendless.services.persistence.common.Entity.addModifiedProperties(Entity.java:319)\n\tat com.backendless.services.persistence.internal.PersistenceService.create(PersistenceService.java:252)\n\tat com.backendless.monitoring.PerformanceMonitoring.invoke(PerformanceMonitoring.java:31)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.proceed(CacheRemoveEntryInterceptor.java:56)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.proceed(CacheRemoveEntryInterceptor.java:31)\n\tat org.jsr107.ri.annotations.AbstractCacheRemoveEntryInterceptor.cacheRemoveEntry(AbstractCacheRemoveEntryInterceptor.java:63)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.invoke(CacheRemoveEntryInterceptor.java:51)\n\tat com.backendless.services.persistence.internal.PersistenceService.create(PersistenceService.java:117)\n\tat jdk.internal.reflect.GeneratedMethodAccessor555.invoke(Unknown Source)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\n\tat com.backendless.dc.manager.DataConnectorChooser.invokeDefaultMethod(DataConnectorChooser.java:157)\n\tat com.backendless.dc.manager.DataConnectorChooser.invoke(DataConnectorChooser.java:85)\n\tat com.sun.proxy.$Proxy196.create(Unknown Source)\n\tat com.backendless.dc.manager.PersistenceProxy.create(PersistenceProxy.java:138)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.services.messaging.DeviceRegistrationPersistenceService.create(DeviceRegistrationPersistenceService.java:74)\n\tat com.backendless.services.messaging.DeviceRegistrationPersistenceService.create(DeviceRegistrationPersistenceService.java:42)\n\tat com.backendless.services.persistence.PersistenceUserValidationDecorator.create(PersistenceUserValidationDecorator.java:243)\n\tat com.backendless.services.persistence.PersistenceUserValidationDecorator.create(PersistenceUserValidationDecorator.java:44)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.lambda$create$14(PersistenceCustomLogicDecorator.java:242)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidationUnsafe(ModelCodeExtender.java:150)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidation(ModelCodeExtender.java:105)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidation(ModelCodeExtender.java:92)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.performActionWithValidation(PersistenceCustomLogicDecorator.java:511)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.create(PersistenceCustomLogicDecorator.java:243)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.create(PersistenceCustomLogicDecorator.java:73)\n\tat com.backendless.services.persistence.common.PersistenceAnalyticsDecorator.create(PersistenceAnalyticsDecorator.java:217)\n\tat com.backendless.inject.interceptors.GoogleAnalyticInterceptor.invoke(GoogleAnalyticInterceptor.java:29)\n\tat com.backendless.inject.interceptors.AbstractApiCallInterceptor.lambda$invoke$0(AbstractApiCallInterceptor.java:51)\n\tat com.backendless.services.RunnerService.executeApiCall(RunnerService.java:63)\n\tat com.backendless.inject.interceptors.AbstractApiCallInterceptor.invoke(AbstractApiCallInterceptor.java:48)\n\tat com.backendless.gamification.AbstractGamificationInterceptor.invoke(AbstractGamificationInterceptor.java:66)\n\tat com.backendless.services.persistence.common.PersistenceAnalyticsDecorator.create(PersistenceAnalyticsDecorator.java:40)\n\tat com.backendless.services.persistence.validator.TableExistenceDecorator.create(TableExistenceDecorator.java:312)\n\tat com.backendless.services.persistence.validator.TableExistenceDecorator.create(TableExistenceDecorator.java:32)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.automation.DataAutomationEventsDecorator.create(DataAutomationEventsDecorator.java:201)\n\tat com.backendless.automation.DataAutomationEventsDecorator.create(DataAutomationEventsDecorator.java:30)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.rt.data.DataRTServiceDecorator.create(DataRTServiceDecorator.java:74)\n\tat com.backendless.rt.data.DataRTServiceDecorator.create(DataRTServiceDecorator.java:35)\n\tat com.backendless.services.persistence.common.PersistenceInterfaceAdapter.save(PersistenceInterfaceAdapter.java:322)\n\tat controllers.Persistence.lambda$saveEntity$4(Persistence.java:198)\n\tat com.backendless.async.BackendlessExecutorService.lambda$submit$0(BackendlessExecutorService.java:106)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n","status":500,"headers":{"access-control-allow-origin":"*","access-control-allow-methods":"POST, GET, OPTIONS, PUT, DELETE, PATCH","date":"Fri, 28 Jan 2022 15:25:40 GMT","connection":"close","content-type":"text/plain; charset=UTF-8","content-length":"5752"},"body":"Backendless encountered an error while handling the request. An internal trouble ticket with ID 81D4076F-3ED1-E2AC-FFFD-F08B2DEB2600 has been created and we will be investigating the issue.\nFor input string: \"text\"\njava.lang.NumberFormatException: For input string: \"text\"\n\tat java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\n\tat java.base/java.lang.Integer.parseInt(Integer.java:652)\n\tat java.base/java.lang.Integer.parseInt(Integer.java:770)\n\tat com.backendless.services.persistence.common.Entity.addModifiedFromString(Entity.java:404)\n\tat com.backendless.services.persistence.common.Entity.addModifiedProperties(Entity.java:319)\n\tat com.backendless.services.persistence.internal.PersistenceService.create(PersistenceService.java:252)\n\tat com.backendless.monitoring.PerformanceMonitoring.invoke(PerformanceMonitoring.java:31)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.proceed(CacheRemoveEntryInterceptor.java:56)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.proceed(CacheRemoveEntryInterceptor.java:31)\n\tat org.jsr107.ri.annotations.AbstractCacheRemoveEntryInterceptor.cacheRemoveEntry(AbstractCacheRemoveEntryInterceptor.java:63)\n\tat org.jsr107.ri.annotations.guice.CacheRemoveEntryInterceptor.invoke(CacheRemoveEntryInterceptor.java:51)\n\tat com.backendless.services.persistence.internal.PersistenceService.create(PersistenceService.java:117)\n\tat jdk.internal.reflect.GeneratedMethodAccessor555.invoke(Unknown Source)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\n\tat com.backendless.dc.manager.DataConnectorChooser.invokeDefaultMethod(DataConnectorChooser.java:157)\n\tat com.backendless.dc.manager.DataConnectorChooser.invoke(DataConnectorChooser.java:85)\n\tat com.sun.proxy.$Proxy196.create(Unknown Source)\n\tat com.backendless.dc.manager.PersistenceProxy.create(PersistenceProxy.java:138)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.services.messaging.DeviceRegistrationPersistenceService.create(DeviceRegistrationPersistenceService.java:74)\n\tat com.backendless.services.messaging.DeviceRegistrationPersistenceService.create(DeviceRegistrationPersistenceService.java:42)\n\tat com.backendless.services.persistence.PersistenceUserValidationDecorator.create(PersistenceUserValidationDecorator.java:243)\n\tat com.backendless.services.persistence.PersistenceUserValidationDecorator.create(PersistenceUserValidationDecorator.java:44)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.lambda$create$14(PersistenceCustomLogicDecorator.java:242)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidationUnsafe(ModelCodeExtender.java:150)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidation(ModelCodeExtender.java:105)\n\tat com.backendless.servercode.codeModel.ModelCodeExtender.performActionWithValidation(ModelCodeExtender.java:92)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.performActionWithValidation(PersistenceCustomLogicDecorator.java:511)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.create(PersistenceCustomLogicDecorator.java:243)\n\tat com.backendless.services.persistence.common.PersistenceCustomLogicDecorator.create(PersistenceCustomLogicDecorator.java:73)\n\tat com.backendless.services.persistence.common.PersistenceAnalyticsDecorator.create(PersistenceAnalyticsDecorator.java:217)\n\tat com.backendless.inject.interceptors.GoogleAnalyticInterceptor.invoke(GoogleAnalyticInterceptor.java:29)\n\tat com.backendless.inject.interceptors.AbstractApiCallInterceptor.lambda$invoke$0(AbstractApiCallInterceptor.java:51)\n\tat com.backendless.services.RunnerService.executeApiCall(RunnerService.java:63)\n\tat com.backendless.inject.interceptors.AbstractApiCallInterceptor.invoke(AbstractApiCallInterceptor.java:48)\n\tat com.backendless.gamification.AbstractGamificationInterceptor.invoke(AbstractGamificationInterceptor.java:66)\n\tat com.backendless.services.persistence.common.PersistenceAnalyticsDecorator.create(PersistenceAnalyticsDecorator.java:40)\n\tat com.backendless.services.persistence.validator.TableExistenceDecorator.create(TableExistenceDecorator.java:312)\n\tat com.backendless.services.persistence.validator.TableExistenceDecorator.create(TableExistenceDecorator.java:32)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.automation.DataAutomationEventsDecorator.create(DataAutomationEventsDecorator.java:201)\n\tat com.backendless.automation.DataAutomationEventsDecorator.create(DataAutomationEventsDecorator.java:30)\n\tat com.backendless.services.persistence.ContextServiceWrapper.create(ContextServiceWrapper.java:125)\n\tat com.backendless.rt.data.DataRTServiceDecorator.create(DataRTServiceDecorator.java:74)\n\tat com.backendless.rt.data.DataRTServiceDecorator.create(DataRTServiceDecorator.java:35)\n\tat com.backendless.services.persistence.common.PersistenceInterfaceAdapter.save(PersistenceInterfaceAdapter.java:322)\n\tat controllers.Persistence.lambda$saveEntity$4(Persistence.java:198)\n\tat com.backendless.async.BackendlessExecutorService.lambda$submit$0(BackendlessExecutorService.java:106)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n"}

Hello,

We need steps to reproduce the problem.

Regards,
Mark

Hi,

Couldn’t you track down the problem with this ticket ID: 81D4076F-3ED1-E2AC-FFFD-F08B2DEB2600

No, it gives us the stack trace, but we have no idea what led to that behavior. As a result, steps to reproduce is something that is essential to the problem resolution.