Commit 76ab4ab9 authored by Matija Obreza's avatar Matija Obreza
Browse files

GenerationType.TABLE doesn’t work, use VersionedModelWithoutId or...

GenerationType.TABLE doesn’t work, use VersionedModelWithoutId or AuditedVersionedModelWithoutId when necessary
parent 0e7f1249
/*
* Copyright 2017 Global Crop Diversity Trust
*
* 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.genesys.blocks.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
@MappedSuperclass
public abstract class AuditedVersionedModelWithoutId extends VersionedModelWithoutId {
private static final long serialVersionUID = -7370145391469993768L;
@JsonView(JsonViews.Protected.class)
@CreatedBy
@Column(updatable = false)
private Long createdBy;
@JsonView(JsonViews.Protected.class)
@CreatedDate
@Column(name = "createdDate", updatable = false)
private Date createdDate;
@JsonView(JsonViews.Protected.class)
@LastModifiedBy
private Long lastModifiedBy;
@JsonView(JsonViews.Protected.class)
@LastModifiedDate
@Column(name = "lastModifiedDate")
private Date lastModifiedDate;
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(final Long createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(final Date createdDate) {
this.createdDate = createdDate;
}
public Long getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(final Long lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(final Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
......@@ -31,7 +31,7 @@ public class BasicModel implements EntityId, Serializable {
@JsonView({ JsonViews.Update.class, JsonViews.Protected.class })
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false, length = 20)
private Long id = InMemoryIdGenerator.nextId();
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* 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.genesys.blocks.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import com.fasterxml.jackson.annotation.JsonView;
@MappedSuperclass
public abstract class VersionedModelWithoutId implements Serializable, Activatable {
private static final long serialVersionUID = 292945663251323045L;
@JsonView({ JsonViews.Update.class, JsonViews.Protected.class })
@Version
Integer version = null;
/** Active by default! */
@Column(nullable = false)
protected boolean active = true;
public Integer getVersion() {
return version;
}
public void setVersion(final Integer version) {
this.version = version;
}
@Override
public boolean isActive() {
return active;
}
public void setActive(final boolean active) {
this.active = active;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VersionedModelWithoutId other = (VersionedModelWithoutId) obj;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment