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

how to understand the pk generate mechanism when saving model

Former Member
0 Kudos
1,766

Hi Experts,

hybris automatically generate pk when saving model.But the mechanism is not clear to me.

Could you please explain the process?

Thanks in advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

bhavirisetty
Active Participant
0 Kudos

Hi Devin,

Please check the de.hybris.platform.core.PK.createFixedUUIDPK method if you have decompiler.

Refer https://help.hybris.com/6.6.0/hcd/8c2d4abd866910149207b2f33deaf652.html as well,

Note : Hybris creates PK using type code, cluster id(default 0), creation time and it will apply bitwise operation to generate PK.

Thanks

former_member387866
Active Contributor
0 Kudos

Hi Devin,

The business case related to this request needs to be evaluated on ROI and Upgradablility.

Perhaps, this can be implemented higher in the hybris stack, and it will be easier to migrate to a later version of hybris. I would suggest that you investigate the AfterSaveListener:

 public class ProductUpdateAfterSaveListener implements AfterSaveListener {
   @Inject private ModelService modelService;

   @Override public void afterSave(final Collection<AfterSaveEvent> events) {
     for (final AfterSaveEvent event : events) {
       if (AfterSaveEvent.UPDATE == event.getType()) {
         //The product deployment code is "1"
         if (1 == event.getPk().getTypeCode()) {
           final ProductModel product = modelService.get(event.getPk());
           //Put your business code here
         }

After Save Listener Documentation for 6.6.

Otherwise, a faster option for you to get an answer would be to decompile the software and debug it.

Regards,
Luke