cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

UUIDs and Unique Semantic Primary Keys

jayme_alonso
Participant
0 Likes
5,216

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

 

Accepted Solutions (1)

Accepted Solutions (1)

jayme_alonso
Participant

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 

 

 

Answers (1)

Answers (1)

peterpersiel
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Jayme,

Number Range Solution could be used to retrieve unique numbers.

Best regards,
Peter

jayme_alonso
Participant
0 Likes

Hi Peter,

Thank you for your response. Maybe I was not clear in the description. I'm talking about a table with related keys, not ones generating new records. For example, an Order Partners table where I have the key (Order/Partner Function/Partner), and I have to guarantee that the Partner appears only once for the same Order/Partner Function.

WRoeckelein
Active Participant
0 Likes

Hi Peter,

besides the original problem being a bit different, the question here would also: When/Where in RAP you should call the numer range function?

Regards,

Wolfgang

peterpersiel
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi colleagues,

sorry then I go the question wrong.

To answer the original question then: it sounds like uniqueness checks would have to be implemented, there is a precheck operation which can be use depending on the scenario - Uniqueness Check for Primary Keys 

Regarding usage of Number Range Solution in RAP: Developing Early Unmanaged Numbering includes an example for numbering using Number Range solution

Best Regards,
Peter