/** * Licensed to the Austrian Association for Software Tool Integration (AASTI) * under one or more contributor license agreements. See the NOTICE file * distributed with this work for additional information regarding copyright * ownership. The AASTI licenses this file to you 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.openengsb.core.edb.jpa.internal; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; @SuppressWarnings("serial") @MappedSuperclass public abstract class VersionedEntity implements Serializable { @Id //FIXME [OPENENGSB-1938] Change back, once Liquibase Synch is implemented. // @TableGenerator(name = "OPENENGSB_ID", table = "OPENENGSB_ID", allocationSize = 1) // @GeneratedValue(generator = "OPENENGSB_ID", strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") private Long id; @Version @Column(name = "VERSION") private Long version; @Column(name = "CREATION_DATE") @Temporal(TemporalType.TIMESTAMP) private Date creationDate; @Column(name = "UPDATE_DATE") @Temporal(TemporalType.TIMESTAMP) private Date updateDate; @PrePersist public void prePersist() { if (creationDate == null) { creationDate = new Date(); updateDate = new Date(creationDate.getTime()); } } @PreUpdate public void preUpdate() { updateDate = new Date(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Long getVersion() { return version; } public void setVersion(Long version) { this.version = version; } public Date getUpdateDate() { return updateDate; } public Date getCreationDate() { return creationDate; } }