Is there any way of retrieving a foreign key in a table without hitting the database for the table the foreign key relates to?
ie
Code:
<hibernate-mapping>
<class
name="eg.BlogItem"
table="BLOG_ITEMS"
dynamic-update="true"
lazy="true">
<id
name="id"
column="BLOG_ITEM_ID">
<generator class="native"/>
</id>
<property
name="title"
column="TITLE"
not-null="true"/>
<property
name="text"
column="TEXT"
not-null="true"/>
<property
name="datetime"
column="DATE_TIME"
not-null="true"/>
<many-to-one
name="blog"
column="BLOG_ID"
not-null="true"/>
</class>
</hibernate-mapping>
with class definition
Code:
package eg;
import java.text.DateFormat;
import java.util.Calendar;
public class BlogItem {
private Long _id;
private Calendar _datetime;
private String _text;
private String _title;
private Blog _blog;
public Blog getBlog() {
return _blog;
}
public Calendar getDatetime() {
return _datetime;
}
public Long getId() {
return _id;
}
public String getText() {
return _text;
}
public String getTitle() {
return _title;
}
public void setBlog(Blog blog) {
_blog = blog;
}
public void setDatetime(Calendar calendar) {
_datetime = calendar;
}
public void setId(Long long1) {
_id = long1;
}
public void setText(String string) {
_text = string;
}
public void setTitle(String string) {
_title = string;
}
}
I would just like to get the actual content of the Blog column from a BlogItem rather than going BlogItem.getBlog().getId() which will persist Blog from the database which is unecessary as I only want the id which will be the foreign key in the BlogItem table. Assume lazy initialisation is being used.
Cheers.
Myk.