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

de.bwaldvogel.mongo.entity.Person Maven / Gradle / Ivy

There is a newer version: 1.45.0
Show newest version
package de.bwaldvogel.mongo.entity;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Document
@TypeAlias("person")
public class Person {

    @Id
    private ObjectId id;

    private String name;

    @Indexed(unique = true)
    @Field("ssn")
    private int socialSecurityNumber;

    @DBRef
    private List accounts;

    protected Person() {
    }

    public Person(String name, int socialSecurityNumber) {
        this.name = name;
        this.socialSecurityNumber = socialSecurityNumber;
    }

    public ObjectId getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getSocialSecurityNumber() {
        return socialSecurityNumber;
    }

    public List getAccounts() {
        return accounts;
    }

    public void addAccount(Account account) {
        if (accounts == null) {
            accounts = new ArrayList<>();
        }
        accounts.add(account);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy