Just getting id column value not using join in hibernate object one to many relation

前端 未结 3 907
南笙
南笙 2020-12-06 19:43

I\'m using hibernate 4+.

I have two sample tables.

Table A

public class A {
  @Id
  private int id;

  @OneToMany(fetch=LAZY)
  private List&         


        
3条回答
  •  半阙折子戏
    2020-12-06 20:26

    You can define two fields in B, one representing the relationship, and the other just the column:

      @ManyToOne(fetch=LAZY)
      @JoinColumn(name="b_id")
      private A a;
    
      @Column(name="b_id", updatable=false,insertable=false) //Or correct column
      private int a_id;
    

    This way you can access entity A or just A's id from entity B.

提交回复
热议问题