简体   繁体   English

与JoinTable的单向OneToMany关系-未生成表

[英]Unidirectional OneToMany relation with JoinTable - table not generated

I tried to create an unidirectional OneToMany relation with a JoinTable in Play Framework 2.1. 我试图在Play Framework 2.1中使用JoinTable创建单向OneToMany关系。 However, the framework is not generating the 'JoinTable': "transformation_input_files". 但是,该框架未生成“ JoinTable”:“ transformation_input_files”。 The strange part is that if I change the relation to ManyToMany the table is generated. 奇怪的是,如果我将关系更改为ManyToMany,则会生成表。 Here is the code: 这是代码:

So its about an Transformation class containing multiple S3Files. 因此,它涉及包含多个S3Files的Transformation类。 Here is the Transformation file: 这是转换文件:

@Entity
@Table(name = "transformations")
public class Transformation extends Model {

    @Id
    public Long id;

    /*...*/

    @OneToMany(cascade = CascadeType.PERSIST)
    @JoinTable(
        name="transformation_input_files",
        joinColumns = @JoinColumn( name="transformation_id"),
        inverseJoinColumns = @JoinColumn( name="input_file_id")
    )
    public List<S3File> inputFiles;
}

Here is the S3File: 这是S3File:

@Entity
@Table(name="s3files")
public class S3File extends Model {

    @Id
    public Long id;

    /*...*/
}

The S3Files are used in more models, so that can not be a bidirectional relation. S3Files在更多模型中使用,因此不能是双向关系。 If I change @OneToMany in @ManyToMany it does generate the join table, however, I do like to stick with the @OneToMany relation. 如果我在@ManyToMany中更改@OneToMany,它的确会生成联接表,但是,我想坚持使用@OneToMany关系。

How do I solve this problem? 我该如何解决这个问题? Did I missed something? 我错过了什么吗?

In one-to-many relationship you have to store the relation in "Many" entity..if you don't want to store the value in the S3File class you have to create another class to join the two classes. 在一对多关系中,您必须将关系存储在“许多”实体中。如果您不想将值存储在S3File类中,则必须创建另一个类以将这两个类连接在一起。

Example:
@Entity
@Table(name="transformations_ s3files")
public class Relation extends Model {
    @Id
    public Long id;

    @ManyToOne
    public Transformation transformation;        

    @OneToOne
    public S3File file;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java持久性的单向oneToMany关系 - unidirectional oneToMany relation with java persistence 在JoinTable中使用Criteria在休眠的单向OneToMany关系中获取子类 - Using Criteria get child class in unidirectional OneToMany relationship in hibernate with JoinTable 在删除元素时,Hibernate单向OneToMany映射中的约束违反,包括JoinTable和OrderColumn - Constraint violation in Hibernate unidirectional OneToMany mapping with JoinTable and OrderColumn when removing elements 为什么要在 Java 中使用 @JoinTable 注释而不是单向 @OneToMany 注释 - Why would you use @JoinTable annotation instead of Unidirectional @OneToMany annotation within Java JPA / Hibernate:双向OneToMany / ManyToOne关系仅适用于单向 - JPA/Hibernate: bidirectional OneToMany/ManyToOne relation only works unidirectional Hibernate不保存到联接表中-ManyToOne和JoinTable关系 - Hibernate not saving into join table - ManyToOne and JoinTable relation JPA 2.0(Hibernate)使用@JoinTable为@OneToMany生成了不正确的联接表PK - JPA 2.0 (Hibernate) generates incorrect join table PK for @OneToMany with @JoinTable 如何在 Hibernate 中创建具有单向关系的表? - How to create table with unidirectional relation in Hibernate? 按 OneToMany 关系表中的属性过滤 - Filtering by properties in OneToMany relation table @OneToMany @JoinTable错误 - @OneToMany with @JoinTable error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM