gpt4 book ai didi

java - hibernate HiLo - 所有实体的一张表

转载 作者:行者123 更新时间:2023-12-01 15:30:19 24 4
gpt4 key购买 nike

我见过这个问题

NHibernate HiLo - one table for all entities

所以我读过

http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/

我尝试在 hibernate 状态下执行此操作。 hibernate 不会检查属性 HashMap 中的“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 表的结构如下:

实体名称 |下一个高值

最佳答案

我已经成功地做到了我想要的,不是每个表的行,而是每个表的列。

它是这样的:在我的 myHiloTable 上,每个实体一列,我想使用 hilo 来生成 id。所以它将是一个一行多列的表格。

我的希洛表:

实体1 |实体2 |实体3

entity2 的配置示例是:

<id name="whateverYourIdNameIs" type="java.lang.Integer">
<column name="whateverYourColumnNameIs" />
<generator class="hilo">
<param name="table">myHiloTable</param> //tablename is same for all entities
<param name="column">entity2</param> //column name changes for entity
</generator>
</id>

关于java - hibernate HiLo - 所有实体的一张表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9602061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com