I've seen this question
NHibernate HiLo - one table for all entities
and so I've read
http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/
and i tried to do it on hibernate . hibernate does not check the "where" key in the properties hashmap so i try to override the configure function myself but i cant read or update the value.
is there a ready solution for this ? my code is below.
@Override
public void configure(Type type, Properties params, Dialect dialect)
{
tableName="myTableNameForHiloValues"; //hardcoded
columnName="NextHiValue";//the column that holds the next hi value
String schemaName = params.getProperty(SCHEMA);
String catalogName = params.getProperty(CATALOG);
tableName = Table.qualify( catalogName, schemaName, tableName );
query = "select " + columnName +
" from " //+ dialect.appendLockHint(LockMode.UPGRADE, tableName) +
dialect.getForUpdateString() +
" where EntityName='"+params.getProperty("target_table")+"'"
//here i give the entity that i want to use
;
update = "update " + tableName +
" set " + columnName + " = ? "+
" where " + columnName + " = ?"+
" and EntityName='"+params.getProperty("target_table")+"'"
;
}
the structure of the myTableNameForHiloValues table is like :
EntityName | NextHiValue