I want a DB generated value on INSERT and on UPDATE.
This value must be persisted, hence, AFAIK, formula cannot be used.
This value is, afterwards, used as a criteria for search.
Exemple :
To generate something like :
Code:
INSERT INTO employee (ename, soudexcode) VALUES ('Achille', 'SOUNDEX('Achille'));
I'd like to write something like :
Code:
@Column(name="ename")
private String name;
@Column(updatable=true, insertable=true, name="soundexcode")
@Generated(GenerationTime.ALWAYS, formula='SOUNDEX(name)')
private String soundexCode;
which may be a bit tricky because of parameter substitution.
The following proposition should be more flexible and quite simplier to implement :
Code:
@Column(updatable=true, insertable=true, name="soundexcode")
@Generated(GenerationTime.ALWAYS, formula=methodToComputeSQLStringFromThisInstance())
private String soundexCode;
with :
Code:
public String methodToComputeSQLStringFromThisInstance()
{
return "SOUNDEX("+name+")";
}
which has no parameter substition and is quite simple !
I'd just like to generate my INSERT/UPDATE SQL statement per column, and not per table as it is possible now.
Hence, I don't have to maintain a SQL query. I still use hibernate to generate it for me.
This way, I don't have to INSERT, then SELECT, then UPDATE then re-SELECT my row in order to get a DB-computed value.
I don't want to use a database trigger where there is no need for a database trigger.