I have a situation where it would be useful to be able to retrieve an entity from a @ManyToOne mapping, but also set the property by ID. So when I accessing an existing record I can easily read access the associated entities, but when defining associated entities I only need a primary key rather than constructing a complete entity.
So, using the same column of "TagID", I would like to refer to the associated Tag entity/class like so:
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "TagID", nullable = false) @NotNull public Tag getTag() { return this.tag; }
public void setTag(Tag tag) { this.tag = tag; }
But also as a simple Integer value, like so:
@Column(name = "TagID", nullable = false) public Integer getTagId() { return this.tagId; }
public void setTag(Integer tagId) { this.tagId = tagId; }
Does hibernate support this?
|