Tried to create UserAccount, then login in the same service.
I have to first create a UserAccount, then break transaction, then commit , then start a new transaction , then login and get loginkey.
If all in one transaction , when getLoginkey function tries to create a new UserLoginKey record, it will get an error that states the new created userAccount’s userId is not found in the userAccount table.
The service is called through restApi, moqui framework version 3.0.0.
Someone has a clue?
UserFacade.getLoginKey() will always create the record for the key in a separate transaction. There are a few framework things like this, run in a separate transaction to keep the maintenance of the data isolated from application logic (and the eventual commit or rollback of the transaction of whatever called it). The same thing is done for entity ID sequencing, certain SystemMessage operations, etc.
This helps with more reliable framework operation, but on certain entities with foreign keys you have to code around it. In other words, yes the UserAccount record must exist in the database (committed data) before you can call getLoginKey().
Thank you for the explanation. Then I know I am walking on the right direction.