设置:
- Oracle 11g Enterprise Edition Release 11.2.0.1.0 64bit Production
- Toad For Oracle 12.1.0.22
- 休眠 4.0.0.4000
- 流畅的休眠 2.0.1.0
- 项目在 C# 4.5.1 下开发
流畅的配置:
var configuration = Fluently.Configure()
.Database(OracleManageDataClientConfiguration.Oracle10
.ConnectionString("my-connection-string")
.IsolationLevel(IsolationLevel.ReadCommitted).ShowSql())
.Mappings(x => x.FluentMappings.AddFromAssembly(my-assembly)
.Convention.Add<CustomIdentityHiloConvetion>())
.ExposeConfiguration(buildSchema)
.BuildConfiguration();
流利的约定:
public class CustomIdentityHiloConvetion : IIdConvention
{
public void Apply(IIdentityInstance instance)
{
instance.GeneratedBy.HiLo("NEXTHIVALUETABLE", "NEXTHIVALUECOLUMN", 10, builder =>
builder.AddParam("where", string.Format("{0} = '{1}'", "TABLENAME", instance.EntityType.Name.ToUpperInvariant())));
}
}
从 Nhibernate 生成的 SQL 语句: select NEXTHIVALUECOLUMN from NEXTHIVALUETABLE where TABLENAME = 'MYSAMPLETABLE' 进行更新
它抛出错误,它无法使用该语句从表 NEXTHIVALUETABLE 中读取 hi 值。我直接在 Toad 中执行上述语句并运行得非常好和 SQLite 表。
我用来自 Nhibernate.Id 命名空间的 TableGenerator 类(第 193 行)中的 command.ExecuteReader 语句反汇编(使用 resharper)Nhibernate 程序集,因此它抛出了这个异常。
DoWorkInCurrentTransaction 方法的快速代码:
do
{
IDbCommand command = conn.CreateCommand();
IDataReader rs = (IDataReader) null;
command.CommandText = this.query; // select NEXTHIVALUECOLUMN from NEXTHIVALUETABLE where TABLENAME = 'MYSAMPLETABLE' for update
command.CommandType = CommandType.Text;
command.Transaction - transaction;
PersistentIdGeneratorParmsNames.SqlStatementLogger.LogCommand("Reading high value: ", command, FormatStyle.Basic);
try
{
rs = command.ExecuteReader();
if(!rs.Read())
{
string message = !string.IsNullOrEmpty(this.whereClause) ? string.Format("could not read a hi value from table '{0}' using the where class ({1})- you need to populate the table"....//more statements);
TableGenerator.log.Error((object)message);
throw new IdentifierGeneratorException(message);
}
num1 = Convert.ToInt64(this.columnType.Get(rs, 0));
}
catch(Exception ex)
{
//more statements
}
//more statements
...
...
...
}