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