I have a table in database and a function that takes the table’s id and returns some number, for instance (I use Oracle syntax, but I believe RDMS doesn’t really matter in this case),
CREATE TABLE test1( test1_id INT NOT NULL PRIMARY KEY,
val VARCHAR(50));
CREATE FUNCTION getNum (id IN test1.test1_id%type) RETURN NUMBER IS ....
In my hibernate data object class I want to add a property which holds result of function execution. What is the right way to do so using annotations ?
@javax.persistence.Table(name = "test1", schema = "test", catalog = "")
@Entity
public class Test1Entity
{
private int test1Id;
@Column(name = "test1_id", nullable = false, insertable = true,
updatable = true, length = 22, precision = 0)
@Id
//get/set
...
// is it possible to use annotations,
// so it will call a function to populate this field ?
private BigDecimal test_num;
}
I was thinking about creating naming native query , something like SELECT a.test1_id, a.val, getNum(a.test1_id) as test_num FROM test1 a WHERE a.test1_id = :param_test1_id, but it means I cannot use Session.get for reading object from DB.
Thank you.
Use this: