0

I want to use Java Persistence to create multiple tables that share a subset of columns but can't figure out the magic syntax.

@Data
@NoArgsConstructor
public class SubClass extends Auditable {

  @Column(name = "foo")
  private String foo;
}

@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "A")
public class SuperClassA extends SubClass{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int lorum;
}

@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "B")
public class SuperClassB extends SubClass{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int ipsum;
}

The end result of this would be two tables

Table A with fields lorum and foo
and
Table B with fields ipsum and foo

moondc
  • 372
  • 1
  • 5
  • 18
  • 1
    The answear to you question should be here - [SO](https://stackoverflow.com/questions/997203/jpa-how-to-use-the-same-class-entity-to-map-different-tables) – Chaosfire Jan 25 '22 at 16:31
  • If you want to copy paste the answer from this post, I'll accept it as the solution. – moondc Jan 26 '22 at 14:28

0 Answers0