Hybris generates an existing PK
Asked Answered
H

2

5

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?

Hutchings answered 12/2, 2018 at 10:2 Comment(4)
Did you run an update system after the upgrade?Corrective
@Corrective Yes I did, It is mandatory since we have some new Types/Relations/Attributes.Hutchings
@MohamedNabli, 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.Greysun
this might work but we have this issue almost on all tables. @GreysunHutchings
H
3

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.

Hutchings answered 14/2, 2018 at 9:42 Comment(0)
E
3

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.

Eleanore answered 12/2, 2018 at 11:44 Comment(1)
This could help, it was enough for us to read the algorithme. Meanwhile I was checking the behavior on a virgin database.Hutchings
H
3

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.

Hutchings answered 14/2, 2018 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.