Use same parent table id in daughter - Hibernate

Asked

Viewed 319 times

0

I’m having trouble setting up and treating the use of ID in parent/child classes using Hibernate. I get everything to work properly when the record does not exist in the parent table (records are created with id correct in father and daughter tables), but when the record exists in the parent table and I need to insert it only in the daughter, a new id is created. I need Ids to stay the same on both tables

Parent class:

==========================
@Entity
@Table(name = "FUNDOS" , schema = "LIMITE")
@Inheritance(strategy = InheritanceType.JOINED)
public class Fundo implements Comparable<Fundo>, FundoInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Integer id;   

======================

Classe Filha:

======================
@Entity
@Table(name = "BENCHMARKS" , schema = "LIMITE")
public class Benchmark extends Fundo {


    Benchmark() {
    }

    public Benchmark(Fundo fundo) {
        this.id = fundo.getId();
        this.nome = fundo.getNome();
        this.codigoX = fundo.getCodigoX();
        this.codigoY = fundo.getCodigoY();
    }

============

How to treat ?

I’ve tried reverse engineering to know which notes the Hibernate generate from the tables already created...

  • Already tried to use @Primarykeyjoincolumn("ID") in the Benchmark Table?

  • Yes... I have consulted manuals and all the tutorials available. I used @Primarykeyjoincolumn and it didn’t work ..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.