-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Map a column, and an entity?
PostPosted: Wed Apr 27, 2011 7:41 pm 
Newbie

Joined: Wed Apr 27, 2011 7:34 pm
Posts: 2
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.