[英]OneToMany and JoinColumn annotations is separate
I'm using hibernate 3.2.1. 我正在使用休眠3.2.1。 In an entity class I've seen the annotations
@OneToMany
and @JoinColumns
are always used together. 在实体类中,我已经看到
@OneToMany
和@JoinColumns
注释始终一起使用。 But what do these mean in separate? 但是这些分别意味着什么? For instance what it would mean if we annotated our entity class as follows:
例如,如果我们对实体类进行如下注释,那将意味着什么:
@Entity
@Table(name = "player_account")
public class PlayerAccount {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@ManyToOne(targetEntity = Player.class, fetch = FetchType.EAGER)
//Without @JoinColumn
private Player player;
//GET, SET
}
Please see what says Hibernate documentation about it: http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/ You need 2.2.5.2. 请参阅有关此文件的Hibernate文档: http : //docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/您需要2.2.5.2。 Many-to-one section: The @JoinColumn attribute is optional, the default value(s) is like in one to one, the concatenation of the name of the relationship in the owner side, _ (underscore), and the name of the primary key column in the owned side.
多对一部分:@JoinColumn属性是可选的,默认值是一对一的,所有者名称中的关系名称_(下划线)的串接,拥有方的主键列。
@OneToMany
annotation defines a many-valued association with one-to-many multiplicity. @OneToMany
批注定义具有一对多@OneToMany
的多值关联。 If the collection is defined using generics to specify the element type, the associated target entity type need not be specified; 如果使用泛型定义集合以指定元素类型,则无需指定关联的目标实体类型; otherwise the target entity class must be specified
否则,必须指定目标实体类
@JoinColumn
is used to specify a mapped column for joining an entity association. @JoinColumn
用于指定用于加入实体关联的映射列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.