My hybris development environment test

I am using my company mac pro 2015 for a lot of thing. So I need different environment look like C#, hybris, ABAP, etc. These environment needs needs service look like db. These service using my ram always. So I am using VM for environment which are not used often. I created VM for new hybris versions for testing (docker cannot pause / resume systems yet). I try some scenarios for my best hybris development environment.

VM: OS version Centos 7, Java 8 u162, MySQL 5.7.21 and hybris version 6.6.

Enviroment Compile time (ant clean all)
Hybris files in host shared with guest vm 21 minutes 9 seconds
Hybris files in guest vm 3 minutes 8 seconds

Creating history for item

If you want create history for item look like backoffice, you can use below example.

public void updateConsignmentStatus(String userUid, ConsignmentModel consignment, ConsignmentStatus status) {
  Map originals = new HashMap();
  originals.put(ConsignmentModel.STATUS, consignment.getStatus());


  Map news = new HashMap();
  news.put(ConsignmentModel.STATUS, consignment.getStatus());

  final SavedValues savedValues = JaloConnection.getInstance().logItemModification(consignment.getPk(), news, originals, false);

Creating,updating or deleting other items in interceptor

public class MyCustomerPrepareInterceptor implements PrepareInterceptor {
  private static final Logger LOG = Logger.getLogger(MyCustomerPrepareInterceptor.class);

  public void onPrepare(CustomerModel customerModel, InterceptorContext interceptorContext) throws InterceptorException {

    final MyItemModel myItem = interceptorContext.getModelService().create(MyItemModel.class);
    //interceptorContext.registerElementFor(myItem, PersistenceOperation.DELETE);


DB connection for DDL in groovy


In hybris hac, you cannot run DDL (data definition language) commands. You need unprotected connection to db. You can use below example. DDL commands are dangerous!!!

import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

def config = spring.getBean("configurationService").getConfiguration();

DriverManagerDataSource dataSource = new DriverManagerDataSource();
JdbcTemplate jdbc = new JdbcTemplate(dataSource)

Using separate file for different class logging

Below example logging flexiblesearch class to separate file with time based trigger policy. Also we can add rollover strategy for removing old files.

log4j2.appender.FlexlogAppender.ImmediateFlush=true log4j2.appender.FlexlogAppender.layout.type=PatternLayout
log4j2.appender.FlexlogAppender.layout.pattern=%m%n log4j2.appender.FlexlogAppender.policies.type = Policies
log4j2.appender.FlexlogAppender.policies.time.type = TimeBasedTriggeringPolicy log4j2.appender.FlexlogAppender.policies.time.interval = 1000000
log4j2.appender.FlexlogAppender.policies.time.modulate = true = de.hybris.platform.jalo.flexiblesearch
log4j2.logger.flexible.level = DEBUG log4j2.logger.flexible.appenderRef.stdout.ref = FlexlogAppender log4j2.logger.flexible.additivity = false

Known hybris strategies

Strategy Interface Description
DefaultCommerceCloneSavedCartStrategy  Clone cart.
DefaultCloneAbstractOrderStrategy  Clone order.
DefaultCommerceAddToCartStrategy CommerceAddToCartStrategy Adding product to cart.
DefaultMultiCodeCouponRedemptionStrategy CouponRedemptionStrategy<>  Single code coupon redemption.
DefaultSingleCodeCouponRedemptionStrategy CouponRedemptionStrategy<>   Multi code coupon redemption.


Delete all item by type

You can delete all item by type with impex. Below example removing all stock levels.
REMOVE StockLevel[batchmode=true];itemType(code)[unique=true]

Update object private property with groovy

You can update private field an object with below sample code.

def myBean = spring.getBean("myBean");

def f = myBean.getClass().getDeclaredField("myField");
f.set(myBean, "new string value");

Changing item attribute type in hybris

Some times you need attribute type change in hybris. Hybris as own ORM and it is not support updating attribute type. If you change attribute type you will get error like this:

de.hybris.platform.servicelayer.exceptions.ModelSavingException: <########## NewPropError ##########> value type mismatch in unlocalized property ‘myproperty’ of ‘myitem’ : expected ‘class java.lang.Integer’ but got ‘class java.lang.Long’

If you don’t want to adding new field than migrating data and removing old, you can use below procedure.

  • Change column type in DB. You cannot do this on hac because DDL disabled.
  • Update system in hac (Platform -> Update without Create essential data option).