简体   繁体   English

如何设置@OneToMany 自动生成表的模式?

[英]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 7Java 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.

相关问题 如何手动设置自动生成的 ID? - How to set autogenerated Id manually? 如何避免 Openjpa 在自动生成的字段中设置 null 值? - How to avoid Openjpa set null value in autogenerated field? 如何在休眠中正确设置双向关联@OneToMany - How to properly set bidirectional association @OneToMany in hibernate 连接表@OneToMany / @ManyToOne - joining tables @OneToMany / @ManyToOne 如何将简单的 Java POJO 转换为 avro schema.avsc 文件,然后转换为自动生成的 avro 记录,最终将其推送到 Kafka 主题中? - How to covert Simple Java POJO to avro schema .avsc file and then to autogenerated avro records to finally push it into Kafka topic? 在 JPA 注释中为 @Embedded 表设置架构? - Set schema for @Embedded tables in JPA annotation? Java Spring JPA - 如何使用 OneToMany 等正确 map 多个表 - Java Spring JPA - How to correctly map multiple tables with OneToMany and such 如何使用 JPA 和 Hibernate 为 2 个表建立单向 @oneToMany 关系 - How to make unidirectional @oneToMany relationship for 2 tables using JPA and Hibernate 如何在JPA中的多个表之间代表OneToMany关系? - How do I repsent OneToMany relationship in JPA with multiple tables inbetween? 访问Netbeans从XML模式自动生成的列表 - Accessing a List autogenerated from XML Schema by Netbeans
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM