Updating database directly using SQL script for entities used by Native app causes database synchronisation error

0
I have a database entity Person with some properties. I retrieve this entity in a Nanoflow of a mobile native app so I can view the entries (objects in the database). This nanoflow is triggered by a button in my Native app. I now run the app it works fine but since there is nothing in the person table so I don’t see anything. I now open the Mendix database viewer and run a script to add a few entries to the Person table. I restart the app in Mendix studio. As soon as I launch the Native app I now get a database synchronisation error and an exception is thrown. You can see the exception at the end of description. If I remove the entries the error is gone and everything is back to normal. My question is, is it an illegal operation to use sql script to update database and the database should only be updated from within the Mendix runtime by using and app. I am using default internal database.   Log level: Error Log node: Connector Message: An error has occurred while handling the request. [User 'Anonymous_9e582d62-fa80-4ca8-b8e0-609848ef3d31' with session id '622a1b26-XXXX-XXXX-XXXX-XXXXXXXX6e7b' and roles 'Administrator'] Stack Trace: java.lang.IllegalArgumentException: Entity id should be not zero     at com.mendix.basis.objectmanagement.SchemeManagerImplBase.getObjectType(SchemeManagerImplBase.java:388)     at com.mendix.basis.objectmanagement.MendixIdentifier.getObjectType(MendixIdentifier.java:86)     at com.mendix.basis.objectmanagement.MendixObjectImpl.setId(MendixObjectImpl.java:307)     at com.mendix.basis.objectmanagement.SchemeManagerImplBase.getInstance(SchemeManagerImplBase.java:141)     at com.mendix.webui.actions.client.RetrieveByXPathAction.$anonfun$retrieveForTemplateGrid$1(RetrieveByXPathAction.scala:131)     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)     at scala.collection.Iterator.foreach(Iterator.scala:941)     at scala.collection.Iterator.foreach$(Iterator.scala:941)     at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)     at scala.collection.IterableLike.foreach(IterableLike.scala:74)     at scala.collection.IterableLike.foreach$(IterableLike.scala:73)     at scala.collection.AbstractIterable.foreach(Iterable.scala:56)     at scala.collection.TraversableLike.map(TraversableLike.scala:238)     at scala.collection.TraversableLike.map$(TraversableLike.scala:231)     at scala.collection.AbstractTraversable.map(Traversable.scala:108)     at com.mendix.webui.actions.client.RetrieveByXPathAction.retrieveForTemplateGrid(RetrieveByXPathAction.scala:130)     at com.mendix.webui.actions.client.RetrieveByXPathAction.apply(RetrieveByXPathAction.scala:63)     at com.mendix.webui.actions.client.RetrieveByXPathAction.apply(RetrieveByXPathAction.scala:30)     at com.mendix.webui.actions.client.RegularClientAction$Helpers$.$anonfun$liftEither$1(RegularClientAction.scala:29)     at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.$anonfun$apply$4(RegularClientAction.scala:55)     at com.mendix.webui.requesthandling.helpers.StateHandling.withState(StateHandling.scala:35)     at com.mendix.webui.requesthandling.helpers.StateHandling.withState$(StateHandling.scala:32)     at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.withState(RegularClientAction.scala:45)     at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:53)     at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:45)     at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$3(RegularClientAction.scala:109)     at scala.util.Try$.apply(Try.scala:213)     at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2(RegularClientAction.scala:109)     at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2$adapted(RegularClientAction.scala:107)     at com.mendix.webui.requesthandling.helpers.ContextHandling.$anonfun$inContext$5(ContextHandling.scala:47)     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)     at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47)     at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32)     at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49)     at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25)     at com.mendix.webui.requesthandling.helpers.ContextHandling$ClientMonitoredAction.monitor(ContextHandling.scala:59)     at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:47)     at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:27)     at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:86)     at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:24)     at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:19)     at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:86)     at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$1(RegularClientAction.scala:107)     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)     at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest(ProfileHandling.scala:14)     at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest$(ProfileHandling.scala:10)     at com.mendix.webui.actions.client.RegularClientAction.profileRequest(RegularClientAction.scala:86)     at com.mendix.webui.actions.client.RegularClientAction.execute(RegularClientAction.scala:104)     at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:104)     at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:81)     at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40)     at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:76)     at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:73)     at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32)     at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:79)     at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:963)     at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)     at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867)     at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)     at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)     at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)     at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)     at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)     at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)     at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)     at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)     at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)     at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)     at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)     at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)     at org.eclipse.jetty.server.Server.handle(Server.java:502)     at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)     at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)     at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)     at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)     at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)     at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)     at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)     at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)     at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)     at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)     at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)     at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)     at java.base/java.lang.Thread.run(Thread.java:834)    
asked
1 answers
2

Hi Mudassar,

In principle using insert statements to update the database Mendix is running on, is not recommended. A challenge is for instance generating the id. See for this my answer to another question some years ago:

https://forum.mendix.com/link/questions/87488

It can be done if you use this answer, but still I wouldn't recommend it. Mendix has it's own mechanism in place to reserve identifiers. If you just generate one yourself based on my answer it could be an identifier is created twice, once via the Mendix identifier reservation system and once with your logic, which could cause unexpected behavior again.

In principle I would only do this manual insert if it is really needed for for instance migration purpose, but not for day to day usage (so as part of microflow / nanoflow commonly used) in a Mendix app

answered