/* * (c) Copyright 2005-2012 JAXIO, www.jaxio.com * Source code generated by Celerio, a Jaxio product * Want to use Celerio within your company? email us at info@jaxio.com * Follow us on twitter: @springfuse * Template pack-backend-sd:src/main/java/project/domain/PersistableHashBuilder.p.vm.java */ package com.company.demo.domain; import java.io.Serializable; import org.apache.log4j.Logger; import org.springframework.data.domain.Persistable; /** * The first time the {@link #hash(Persistable)} is called, we check if the primary key is present or not. * <ul> * <li>If yes: we use it to get the hash * <li>If no: we use a VMID during the entire life of this instance even if later on this instance is assigned a primary key. * </ul> */ public class PersistableHashBuilder implements Serializable { private static final Logger log = Logger.getLogger(PersistableHashBuilder.class); private static final long serialVersionUID = 1L; private Object technicalId; public int hash(Persistable<?> persistable) { if (technicalId == null) { if (!persistable.isNew()) { technicalId = persistable.getId(); } else { technicalId = new java.rmi.dgc.VMID(); log.warn("DEVELOPER: hashCode has changed!." // + "If you encounter this message you should take the time to carefuly " // + "review the equals/hashCode methods for: " + persistable.getClass().getCanonicalName()); } } return technicalId.hashCode(); } }