cancel
Showing results for 
Search instead for 
Did you mean: 

UUIDs and Unique Semantic Primary Keys

jayme_alonso
Participant
0 Kudos

Hi Experts,

I'm working with RAP in BTP and have a question regarding UUIDs and semantic primary keys.

What is the best and recommended way to guarantee the uniqueness of a semantic primary key?

In RAP and OData V4, UUIDs provide us with the ability to create entities in draft mode without needing to validate the keys in the creation popup, which has limitations for more complex checking and responding with messages. Often, these validations result in the popup closing, causing the user to lose the data they have entered and forcing them to re-enter it.

I believe using automatically generated UUIDs allows us to move directly to the edit screen, where we have more control for validations and displaying messages without losing the input data.

I have two options already envisioned for helping me with this issue:

  • Using a validation for create and updating the BO (select in the table and check for uniqueness). Which I'm already using but I think there might be a better way for it
  • Using an unique index in the table and handling the errors. I've not implemented this solution but I imagine would be less cumbersome to implement.

I'm looking forward to hear the input from the colleagues,

Jayme

 

View Entire Topic
jayme_alonso
Participant
0 Kudos

Well, it looks like there is no easier way to do that. I tried to create a unique index in the table, but that only caused a dump and it is not handled by the framework and frontend. Additionally, there is no way to catch that problem in the RAP behavior class and transform it into a nice message (at least not in managed mode).

So my solution was to create a validation for checking the uniqueness of the Semantic Key.

I'll report my solution here for those who come after me:

  1. Added a validation in the behavior.

jayme_alonso_0-1716911485876.png

  • Selected the data in the method created in the Behavior class and checked for uniqueness, returning a reported and failed message. Make sure to exclude the record we're creating/editing (uuid <> actual uuid).

jayme_alonso_1-1716911979823.png

Hope was helpfull for someone.

Cheers

ps: Thank you for the feedback @peterpersiel