I have some entities/tables which I would like to place together in a schema. The intermediary tables from ManyToMany relationships are being generated in the public schema. How do I change the name and schema for the generated table?
@Entity
@Table(schema = "my_schema")
public class AnotherEntity {}
@Entity
@Table(schema = "my_schema")
public class MyEntity {
@ManyToMany
private List<AnotherEntity> entityRelationship;
}
CodePudding user response:
Annotate the relationship with @JoinTable
:
@Entity
@Table(schema = "my_schema")
public class MyEntity {
@ManyToMany
@JoinTable(name="my_intermediary_table", schema="my_schema")
private List<AnotherEntity> entityRelationship;
}