Currently, Hibernate allows me to load objects defined by *-to-one relationships directly with
entity1.getEntity2()
Is it possible to get the foreign key instead of the object?
The current approach which I see is having addint to my mapping:
@JoinColumn(name="message_key")
@ManyToOne(targetEntity=Message.class,fetch=FetchType.LAZY)
private Message message; //these lines currently exist
@Column(name="message_key")
private Long message_fk; //the idea is to add those 2 lines
Is there a better approach to get the foreign key, or is this the only one?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…