简体   繁体   中英

How to change the schema and name for intermediary table generated from relationships

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;
}

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM