Hi all. I have an abstract Entity class, Event, and concrete classes like EventVideo, EventPhoto, etc that extend it. I want to place the object id of the video, photo, etc into the Event table in a column named "item". In entity I have
Code:
@Column(name = "item")
public Long getItem() {return getObjectId();} // abstract, template pattern
public abstract Long getObjectId();
and in EventVideo
Code:
@Override
public Long getObjectId() {
return mediaVideo.getMediaId();
}
I would think this would attempt to write to event.item a value of the mediaId, but I get the error
Code:
[org.hibernate.util.JDBCExceptionReporter] ERROR: column event6_.mediavideo does not exist
When I look at the SQL insert, it never mentions the column "item", but thinks there is a column named "mediavideo".
If I however put the following in EventVideo and remove item from Event, all works perfectly.
Code:
@JoinColumn(name = "item")
@ManyToOne(fetch = FetchType.EAGER)
private MediaVideo mediaVideo;
public MediaVideo getMediaVideo() {return mediaVideo;}
public void setMediaVideo(MediaVideo mediaVideo) {this.mediaVideo = mediaVideo;}
I would Much rather use the broken solution because then I can enforce adding the getObjectId on the concrete method. Any ideas?
Thanks everyone for you help!