I am still looking for a way to get this to work for me. Let me explain what I am doing more clearly. I am migrating an appliction with about 60+ entities from Hibernate 3.0 with mapping files to 3.1 using annotations. I am stuck trying to do the equivalent to the following:
Code:
<class name="Pipe" table="t_pipe">
...
<many-to-one name="offerPrice"
class="pipetracker.model.price.OfferPrice"
formula="( select v_pipe_offerprice.offerprice_fk
from v_pipe_offerprice
where v_pipe_offerprice.id = id )"/>
...
</class>
This works fine for me in both versions of hibernate, but I cannot seem for get the syntax correct for the annotation based mapping.
Code:
@ManyToOne
@Formula(value="( select v_pipe_offerprice.offerprice_fk from v_pipe_offerprice where v_pipe_offerprice.id = id )")
public OfferPrice getOfferPrice() { return offerPrice; }
This is not being considered a formula. The sql inludes a select for the field "pipe.offerprice_id" which does not exist because this is just virtual relationship that is being calculated from a view. I display lists of pipe that have an offerprice based on half a dozen or so properties and I would lke this to be calculated once by the database.
When mapped as in the mapping field my queries are simple:
Code:
from Pipe p where p.offerprice.price > 63.25
or
Code:
from Pipe p where p.offerprice.usr.name = 'jason'
and I can also look up the price in code
Code:
pipe.getOfferPrice().getUsr().getName();
Is this suppported by annotations currently?
If this is not supported can you please suggest an alternate design stragety?