In my model, I have a unique reference ID which is used for business purposes and I also have a primary key for the record used by the internal system. Both use a sequence to generate the unique value.
In hibernate, seems that you can't attach a generator to a property - but I probably wouldn't want to have the DB auto generate the value anyway since my service should be the one to understand how to retrieve the reference ID.
So, I'm just wondering, is the following code the best way to explicitly get the next value from a sequence?
Number nextval = (Number)getHibernateTemplate().execute(
public Object doInHibernate(Session session)
throws HibernateException, SQLException
"select REFERENCE_ID_SEQUENCE.nextval from dual")
result = nextval.longValue();