ORM Duplicate primary key error


We have had an issue for quite some time now which goes as follows:
we use the ORM framework to work with entities. Saving these entities and deleting them goes well. But we also have an external application that has access to the same database (an android app).

So the problem is that when you add an new record through the external way it goes well. But if you try to add a record after that through ORM you get a duplicate primary key error. The only thing I found that helped is to call “ORMReload();”. But that is kinda a heavy method that could give problems, does anyone have an idea how to solve this?

Currently I have rewritten most of the code where I get the new primary key by myself, but we still get it on some parts that I don’t really feel like to rewrite. Is there some way for ORM to update the records before calling “EntityNew”? Thanks in advance!

An example of how we define a primary key in an entity is:

property name=“id” fieldtype=“id” generator=“increment” type=“numeric” ormtype=“integer” length=“11” notnull=“true”;

Also I would like to add that everytime you refresh the page with the error then the primary key goes up with 1 until the error is gone. So weird how it’s totally not looking at what’s in the database.

Don’t forget to tell us about your stack!

OS: Windows Server 2012 R2 (6.3) 64bit
Java Version: 11.0.6 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.31
Lucee Version: Lucee

As I suggested on Stackoverflow, you need to change your entity’s generator attribute from increment to native so that the DB handles primary key creation (using auto increment) instead of the ORM.


Thanks for the advice, we do increment in the database as well so reading that it should be ok to change it to native! I will try it out and see if we get the error in the future. Thanks man!