简体   繁体   English

OneToMany和JoinColumn注释是分开的

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

相关问题 OneToMany UNI和JoinColumn是否可能? - Is OneToMany UNI with JoinColumn possible? @OneToMany关系使用单个@JoinColumn? - @OneToMany relationship using a single @JoinColumn? 与@JoinColumn和@MapKeyColumn保持@OneToMany关系 - Persisting @OneToMany relations with @JoinColumn and @MapKeyColumn Hibernate 使用 OneToMany JoinColumn 插入表 - Hibernate insert table with OneToMany JoinColumn 无法解析 @OneToMany 子表 (@JoinColumn) 的属性 - Could not resolve property of @OneToMany child table (@JoinColumn) 与CASCADE一起在Hibernate中使用JoinColumn创建OnetoMany时遇到问题 - Facing problem while creating OnetoMany with JoinColumn in Hibernate while working with CASCADE JPA @OneToMany + @JoinColumn删除会发布引用表的更新 - JPA @OneToMany + @JoinColumn remove issues an update on referencer table 为什么 @OneToMany 在 JPA 与 springboot 中与 @JoinColumn 的单向关联会产生额外的查询 - why @OneToMany Unidirectional association with @JoinColumn in JPA with springboot generates extra queries 仅使用@mappedBy,no @ JoinColumn-在OneToMany关系中创建的联接列,那么JoinColumn的用途是什么? - Used only @mappedBy , no@JoinColumn - join column created in OneToMany relationship, what is then the use of JoinColumn? DynamoDBMapper 注释。 一对多映射 - DynamoDBMapper Annotations. OneToMany mapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM