Como criar um novo tipo para classes jpa

0 respostas
rafaelgfirmino

Bom pessoal, eu sou novo em java e tenho uma dúvida sobre como criar um novo tipo para as minhas propriedades de entidades jpa utilizando o eclipselink

Aqui é onde eu informo a minha entity que ele vai ter uma propriede do tipo chave

@Column(name = "chave", columnDefinition="VARCHAR(12)")
 private Chave chave;

E aqui está a minha classe Chave

public class Chave implements Serializable {

    private static final String CHARS = "123456789ABCDEFGHIJKLMNPKRSTUVXYZ";
    private static final int SIZE = 12;

    private String chave;

    public Chave(){
        this.chave = gerar();
    }

    public Chave(String chave) throws ChaveException {

        if(chave.length() != SIZE){
            String message = String.format("O tamanho da chave deve ser de %d", SIZE);
            throw new ChaveException(message);
        }

        this.chave = chave;
    }

    public String get(){
        return this.chave;
    }

    public String getChave() {
        return chave;
    }

    public void setChave(String chave) {
        this.chave = chave;
    }

    private String gerar(){
        String hash = "";
        Random r = new Random();

        for (int i = 0; i < SIZE; i++) {
            hash = hash + CHARS.charAt(r.nextInt(CHARS.length()));
        }
        return hash;
    }

}

¬í sr dominio.ChaveZŒv2Ž„1Ž L chavet Ljava/lang/String;xpt GIPIXDRH4F33

Quando estou salvando no banco está indo dessa maneira

Criado 1 de agosto de 2017
Respostas 0
Participantes 1