/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.core.entity;

import com.haulmont.chile.core.annotations.MetaProperty;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.impl.AbstractInstance;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.core.global.UuidProvider;
import com.haulmont.cuba.core.sys.CubaEnhanced;
import org.apache.commons.lang.ObjectUtils;

import javax.persistence.MappedSuperclass;
import java.util.UUID;

/**
 * Base class for not persistent entities.
 *
 * @author Grachev
 * @version $Id$
 */
public abstract class AbstractNotPersistentEntity extends AbstractInstance implements Entity<UUID> {

    private static final long serialVersionUID = -2846020822531467401L;

    protected UUID uuid;

    protected AbstractNotPersistentEntity() {
        uuid = UuidProvider.createUuid();
    }

    public static <T extends AbstractNotPersistentEntity> T create(Class<T> clazz, Entity<UUID> entity) {
        try {
            T t = clazz.newInstance();
            t.uuid = entity.getId();
            return t;
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public UUID getUuid() {
        return uuid;
    }

    @Override
    public MetaClass getMetaClass() {
        return AppBeans.get(Metadata.class).getSession().getClass(getClass());
    }

    @MetaProperty
    @Override
    public UUID getId() {
        return uuid;
    }

    public void setId(UUID id) {
        this.uuid = id;
    }

    @Override
    public void setValue(String property, Object obj, boolean checkEquals) {
        Object oldValue = getValue(property);
        if ((!checkEquals) || (!ObjectUtils.equals(oldValue, obj))) {
            getMethodsCache().invokeSetter(this, property, obj);
            if (!(this instanceof CubaEnhanced)) {
                propertyChanged(property, oldValue, obj);
            }
        }
    }

    @Override
    public String toString() {
        return getClass().getName() + "-" + uuid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AbstractNotPersistentEntity that = (AbstractNotPersistentEntity) o;

        return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null);
    }

    @Override
    public int hashCode() {
        return getId() != null ? getId().hashCode() : 0;
    }
}

@@ -1082,328 +1082,8 @@
 %0D%0A%0D%0A
-    public static %3CT extends AbstractNotPersistentEntity%3E T create(Class%3CT%3E clazz, Entity%3CUUID%3E entity) %7B%0D%0A        try %7B%0D%0A            T t = clazz.newInstance();%0D%0A            t.uuid = entity.getId();%0D%0A            return t;%0D%0A        %7D catch (Throwable e) %7B%0D%0A            throw new RuntimeException(e);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A
     

Remove AbstractNotPersistentEntity.create() method. #PL-3852