I have a view created to display a calculated mapping of one key to another key. I want to annotate this in hibernate to make it accessible from my entity. Being a view, I want this property to be read-only.
The specifics of the situation are as follows:
I have an OrderLineItem. Every OrderLineItem has a list of OrderStatuses. This gives a history for each line item's activity, so we can see a line item was created at time X, approved at time Y, and completed at time Z.
Rather than duplicating data on the OrderLineItem table by specifically keying in the latest status (which we care to look at fairly commonly), we have created a view that displays an OrderLineItem PK and OrderLineItemStatus PK.
My OrderLineItem class on the Java side should have some mapping to this property. Most notably, this is very useful for creating dynamic hibernate Criteria objects for sorting/searching. To accomplish this, I've tried something like:
Code:
@ManyToOne
@JoinTable(name="ORDER_LINE_ITEM_LATEST_STATUS", joinColumns = @JoinColumn(name="LINE_ITEM_ID"), inverseJoinColumns = @JoinColumn( name="STATUS_ID"))
private OrderLineItemStatus latestStatus;
which reads in correctly. However, it attempts to save this property on update/save and delete it on delete. I don't want it to do that, obviously, because the mapped table is actually a view. This isn't a cascading issue since it thinks it wants to be able to just save/update/delete the row of the view that provides the foreign key rather than dig down and modify the entity being pointed at by the key. Rather it's a matter of saying I want this property to be a 'read-only' table join. So if I delete this entity, then this row in the joined table would be untouched. This SOUNDS like an undesirable behavior because it'd give me an orphan row that wouldn't have any meaning -- except this is a view so the row woud be IMPLICITLY deleted, so in this case it DOES make sense.
Also, I don't want it to be transient because I want to read it in initially.
I've tried creating a setLatestStatus method and placing the annotation on that instead but this did not get called. I saw documentation saying that property and method annotations should not be mixed, further making that an invalid solution.
Any ideas?