Quantcast
Viewing all articles
Browse latest Browse all 759

Hibernate id com auto_increment

@Jeanderson_Silva escreveu:

Galera estou com uma dúvida, eu tenho duas tabelas: Contato e Curso
estou utilizando o hibernate 5.2, eu coloquei para hibernate criar os id desta maneira:
Tabela Contato:

@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "contato_id")
    public Integer getId() {
        return this.id.get();
    }

Tabela Curso:

@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "curso_id")
    public int getId(){
        return this.id.get();
    }

Blz até ai tudo bem, mais ao adicionar dois cursos ele faz o id incrementar em sequência. Mas ao adicionar um Contato ele já começa com o ID 3
Ou seja são de tabelas diferentes, mas o contato adicionou a partir do id 3, alguém poderia me explicar?
Ex:
Tabela Curso:
Id--------------nome
1--------------Cabeleireiro
2--------------Web Designer

Tabela Contato
Id--------------nome
3--------------João
4--------------Maria

Se quiserem olhas minhas entidades aqui vai:

@Entity
@Table(name = "cursos")
public class Curso implements Serializable {
    private final IntegerProperty id;
    private final StringProperty nome;
    private final IntegerProperty carga_horaria;

    public Curso() {
        this.id = new SimpleIntegerProperty();
        this.nome = new SimpleStringProperty();
        this.carga_horaria = new SimpleIntegerProperty();
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "curso_id")
    public int getId(){
        return this.id.get();
    }
    
    @Column(name = "nome", length = 60)
    public String getNome(){
        return this.nome.get();
    }
    @Column(name = "carga_horaria")
    public int getCarga(){
        return this.carga_horaria.get();
    }
    
    protected void setId(int id){
        this.id.set(id);
    }
    
    public void setNome(String nome){
        this.nome.set(nome);
    }
    
    public void setCarga(int carga){
        this.carga_horaria.set(carga);
    }
    
    public IntegerProperty idProperty(){
        return this.id;
    }
    
    public IntegerProperty cargaProperty(){
        return this.carga_horaria;
    }
    
    public StringProperty nomeProperty(){
        return this.nome;
    }
}

Minha outra entidade.

@Entity
@Table(name = "contatos")
public class Contato implements Serializable {

    private final IntegerProperty id;
    private final StringProperty nome;
    private final StringProperty telefone;
    private StringProperty observacao;
    private LocalDate data_retorno;
    private Curso curso_pretendido;
    private Situacao situacao;
    
    public Contato() {
        this.id = new SimpleIntegerProperty();
        this.nome = new SimpleStringProperty();
        this.telefone = new SimpleStringProperty();
        this.observacao = new SimpleStringProperty();
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "contato_id")
    public Integer getId() {
        return this.id.get();
    }
    @Column(name = "nome", length = 40, nullable = false)
    public String getNome() {
        return nome.get();
    }
    @Column(name = "telefone", length = 20)
    public String getTelefone() {
        return telefone.get();
    }
    @Column(name = "observacao", columnDefinition = "text")
    public String getObservacao() {
        return observacao.get();
    }
    
    @Column(name = "data_retorno")
    public LocalDate getDataRetorno() {
        return data_retorno;
    }
    @OneToOne()
    @JoinColumn(name = "curso_id")
    public Curso getCursoPretendido() {
        return curso_pretendido;
    }
    @Enumerated(EnumType.STRING)
    @Column(name = "situacao")
    public Situacao getSituacao() {
        return situacao;
    }
    
    public IntegerProperty idProperty() {
        return id;
    }
    
    public StringProperty nomeProperty() {
        return nome;
    }
    
    public StringProperty telefoneProperty() {
        return telefone;
    }
    
    public StringProperty observacaoProperty() {
        return observacao;
    }
    
    protected void setId(int id) {
        this.id.set(id);
    }

    public void setNome(String nome) {
        this.nome.set(nome);
    }

    public void setTelefone(String telefone) {
        this.telefone.set(telefone);
    }

    public void setObservacao(String observacao) {
        this.observacao.set(observacao);
    }
    
    public void setCursoPretendido(Curso curso){
        this.curso_pretendido = curso;
    }
    
    public void setDataRetorno(LocalDate data){
        this.data_retorno = data;
    }

    public void setSituacao(Situacao situacao) {
        this.situacao = situacao;
    }
    
    
}

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 759

Trending Articles


Vimeo 10.7.0 by Vimeo.com, Inc.


Pokemon para colorear


Sapos para colorear


Confidence Quotes – Confident Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


Long Distance Relationship Tagalog Love Quotes


Ligaw Quotes – Courting Quotes – Sweet Tagalog Quotes


INUMAN QUOTES


Re:Mutton Pies (lleechef)


Vimeo 10.7.1 by Vimeo.com, Inc.


tagalog love Quotes – Tiwala Quotes


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Love Quotes – Nagmamahal


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Two timer Sad tagalog Love quotes


5 Tagalog Relationship Rules


Best Love Life Quotes Collection


EASY COME, EASY GO


FORECLOSURE OF REAL ESTATE MORTGAGE



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>