All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pep1.commons.jpa.domain.AbstractUUIDPersistable Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 Leonard Osang
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package pep1.commons.jpa.domain;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.domain.Persistable;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Variation of the {@link AbstractPersistable} for entities that will be exposed via customers through API
 * or other ways, not guessable
 */
@MappedSuperclass
@JsonAutoDetect(
        fieldVisibility = JsonAutoDetect.Visibility.ANY,
        getterVisibility = JsonAutoDetect.Visibility.NONE,
        isGetterVisibility = JsonAutoDetect.Visibility.NONE,
        setterVisibility = JsonAutoDetect.Visibility.NONE)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
public abstract class AbstractUUIDPersistable implements Persistable {

    @Id
    @GenericGenerator(name = "uuid_id", strategy = "pep1.commons.jpa.util.UUIDGenerator")
    @GeneratedValue(generator = "uuid_id")
    private String id;

    @Override
    @JsonIgnore
    public boolean isNew() {
        return id == null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy