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

2
  • 1
    The answear to you question should be here - SO Commented Jan 25, 2022 at 16:31
  • If you want to copy paste the answer from this post, I'll accept it as the solution. Commented Jan 26, 2022 at 14:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.