Commit af08c8ef authored by Matija Obreza's avatar Matija Obreza
Browse files

Added BasicModel#isPersisted() method to consistently test value of the #id

parent 0d1eac8a
......@@ -22,7 +22,9 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
@MappedSuperclass
......@@ -44,6 +46,18 @@ public class BasicModel implements EntityId, Serializable {
this.id = id;
}
/**
* Is the entity persisted to the database? Test is based on value of {@link #id} field where negative integers or
* null mean entity is not yet persisted.
*
* @return true if the {@link #id} is a positive integer, false otherwise
*/
@JsonIgnore
@Transient
public final boolean isPersisted() {
return id != null && id.longValue() > 0;
}
/*
* (non-Javadoc)
*
......
Markdown is supported
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