Mohamed Nabli
Mohamed Nabli

Reputation: 1649

Hybris generates an existing PK

Recently, we have migrated Hybris 5.4 to Hybris 6.5, but ever since it generates an existing PK (we are working with the same database which has some records).

In the development environment, we have :

  1. Deleted All Existing records.
  2. Retried the save Operations till a new PK is generated.

But now we are afraid we will have the same problem in the production, and we cannot do this workaround.

What can we do to make Hybris take the old PK in consideration?

Upvotes: 5

Views: 3144

Answers (2)

Mohamed Nabli
Mohamed Nabli

Reputation: 1649

A previous comment that says :

Do you have this issue for a specific type ? if yes ! You can think to change the deployment table numbre to get a new PK.

this gave me the idea that changing the current counter for PK generation would be the solution, then I prepared a groovy script to do it.

For example, We have order type XML representation defined with typecode : 45.

<itemtype code="Order" extends="AbstractOrder" jaloclass="de.hybris.platform.jalo.order.Order" generate="true" singleton="false" jaloonly="false" autocreate="true">
    <deployment table="orders" typecode="45"/>

so the groovy file to change its counter is :

import de.hybris.platform.core.Registry;
import de.hybris.platform.core.PK.PKCounterGenerator;
import de.hybris.platform.persistence.numberseries.SerialNumberGenerator;

int key = 45;
int current = new de.hybris.platform.core.DefaultPKCounterGenerator().fetchNextCounter(key);
SerialNumberGenerator generator = Registry.getCurrentTenant().getSerialNumberGenerator();
generator.removeSeries("pk_"+key);
generator.createSeries("pk_"+key,1,current*10)

The current solution, solved the issue just for Orders Table. Next step is to make it happen for all tables, this won't be difficult if we use the table numberseries to fetch all existing serieskeys.

Upvotes: 3

homik
homik

Reputation: 563

Check system property (in hac for example) called 'counter.pk.generator.class' there you have a class which generates PK for Hybris items. Open that class and use debugger to see what is wrong with generation.

Upvotes: 3

Related Questions