Using Hibernate Get with Multi-Column Primary Key

好久不见. 提交于 2019-12-01 23:23:47
Koitoer

Try to use and @IdClass or @EmbeddedId

public MyJoinClass implements Serializable {
  private static final long serialVersionUID = -5L;

  @EmbeddedId
  private MyJoinClassKey key;
}

public MyJoinClassKey implements Serializable{

  @Column(name = "ID")
  private long id;

  @Column(name = "EMAIL_ADDRESS_ID")
  private long emailAddressId;
}

Then use

MyJoinClass a = (MyJoinClass )session.get(MyJoinClass .class, new MyJoinClassKey (1, "email"));

Take a look at this question, this is broadly explained. Basically hibernate have a mechanism for compound keys.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!