[英]How to set the schema of @OneToMany autogenerated tables?
I want to put all of the following autogenerated tables into a specific schema.我想将以下所有自动生成的表放入特定模式。
@Entity
@Table(name = "master_table", schema = "test")
public class MasterTable {
@OneToMany
private List<VideoEntity> videos;
@Entity
@Table(name = "video_entity", schema = "test")
public static class VideoEntity {
}
}
Result: there are the two entity tables in test
schema, but also one in the public
schema called master_table_videos
for the list mapping.结果:
test
模式中有两个实体表,但public
模式中也有一个名为master_table_videos
的列表映射。
Question: how can I tell hibernate
to also put the list-mapping table in the same schema than the others?问题:我如何告诉
hibernate
也将列表映射表放在与其他表相同的模式中?
I think you should use the @JoinTable
annotation, at least that allows to set the schema name in standard JPA. 我认为您应该使用
@JoinTable
批注,至少该批注允许在标准JPA中设置架构名称。 Check the JavaDoc for Java EE 7 or Java EE 6 . 检查JavaDoc for Java EE 7或Java EE 6 。
So it would be something like @JoinTable(name = "master_to_videos", schema = "test" )
, and you could also specify the name of the join column if required. 因此,就像
@JoinTable(name = "master_to_videos", schema = "test" )
,如果需要,您还可以指定连接列的名称。
Hibernate将在定义实体的任何persistence.xml中创建表。因此,如果MasterTable和VideoEntity都在persistence.xml中,它将在配置的数据模式中创建这两个表。
I agree with Hein Blöd i tested the @joinTable annotation after any other annotation like @ManyToOne @OneToMany... as for your example it becomes like this我同意Hein Blöd我在任何其他注释(如 @ManyToOne @OneToMany)之后测试了 @joinTable 注释...至于你的例子,它变成了这样
@OneToMany
@JoinTable(schema = "testSchema" )
private List<VideoEntity> videos;
testSchema is interpreted by Hibernate as test-schema testSchema被 Hibernate 解释为test-schema
i know this is for an old question i'm writing this so that any one right now can find the correct answer i search the inte.net and this is the first question i found.
我知道这是针对一个老问题的,我正在写这篇文章,以便现在任何人都可以找到我搜索 inte.net 的正确答案,这是我发现的第一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.