Inheritance Java Web Inheritance

0

I have the inheritance to do below and I would like to know how it would look on main. Could someone here help?

Could you tell me if you have problems with the mapping I did and what would the mainTest look like? I can not set the value of the classLancamentoDespesaParcelado ...

Iuse:1ºtheEclipse;2ndOracledatabaseandtoviewthetablesofthedatabaseIuseoracleSQLDeveloper;
3ºAndintheprojectwewillusethestrategyofmultipletableswithuseofJoin;I'llputthestartofclasses:

RELEASE

@Entity@Inheritance(strategy=InheritanceType.JOINED)@DiscriminatorColumn(NAME="TIPO", discriminatorType=DiscriminatorType.CHAR)
 @Table(name="LANCAMENTO")
 public class Lancamento extends GenericModel{ ... }

SPANISH LANGUAGE

@Entity
public class LancamentoDespesa extends Lancamento{ ... }

RECENT_RUNNERS

@Entity
public class LancamentoReceita extends Lancamento{ ... }

SPANISH LANGUAGE_PARCELED

@Entity
public class LancamentoDespesa extends LancamentoDespesa{ 
    @Column(name = "PARCELA", nullable = true)
    private int numParcela;

    GET/SET...
}

Final remarks: In SQL developer creates the inheritance tables, but also creates 4 other tables with names:

HT_LANCAMENTO  
HT_LANCAMENTODESPESA  
HT_LANCAMENTORECEITA  
HT_LANCAMENTODESPESAPARCELADA  

And all have in the drawing of the table a square with x.

I can not get another photo here if I did not.

    
asked by anonymous 22.04.2017 / 17:01

1 answer

1

Rafael, I copied the code and made the following changes for generating tables to work:

RELEASE

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(NAME="TIPO", discriminatorType=DiscriminatorType.INTEGER)
@Table(name="LANCAMENTO")
public class Lancamento extends GenericModel { ... }

RECENT_RUNNERS

@Entity
@DiscriminatorValue("1")
public class LancamentoReceita extends Lancamento { ... }

SPANISH LANGUAGE

@Entity
@DiscriminatorValue("2")
public class LancamentoDespesa extends Lancamento { ... }

SPANISH LANGUAGE_PARCELED

@Entity
@DiscriminatorValue("3")
public class LancamentoDespesa extends LancamentoDespesa { 
    @Column(name = "PARCELA", nullable = true)
    private int numParcela;

    GET/SET...
}

When you use @Inheritance(strategy = InheritanceType.JOINED) and @DiscriminatorColumn , you must also use the @DiscriminatorValue annotation to set the value that will be used to distinguish the type of the concrete entity.

In my example I switched to DiscriminatorType.INTEGER because using CHAR did not work with Hibernate in my tests.

    
23.04.2017 / 16:37