我看过这个问题
所以我读过
http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/
我试图在休眠状态下做到这一点。hibernate 不检查属性哈希图中的“where”键,所以我尝试自己覆盖配置函数,但我无法读取或更新该值。
有没有现成的解决方案?我的代码如下。
@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")+"'"
;
}
myTableNameForHiloValues 表的结构如下:
实体名称 | 下一个高值