/** * == @Spearal ==> * * Copyright (C) 2014 Franck WOLFF & William DRAI (http://www.spearal.io) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.spearal.jpa2.model; import java.io.Serializable; import java.util.UUID; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Version; /** * @author Franck WOLFF */ @MappedSuperclass public abstract class AbstractEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name="ENTITY_UID", unique=true, nullable=false, updatable=false, length=36) private String uid; @Version private Long version; public AbstractEntity() { this.uid = UUID.randomUUID().toString(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUid() { return uid; } public Long getVersion() { return version; } public void backdoorSetVersion(Long version) { this.version = version; } @Override public int hashCode() { return uid.hashCode(); } @Override public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof AbstractEntity)) return false; return uid.equals(((AbstractEntity)obj).uid); } }