設定:
- Oracle 11g Enterprise Edition リリース 11.2.0.1.0 64 ビット プロダクション
- Oracle 12.1.0.22 のヒキガエル
- ニバネート 4.0.0.4000
- Fluent Nhibernate 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' for update
ステートメントを使用してテーブル NEXTHIVALUETABLE から hi 値を読み取ることができなかったというエラーがスローされます。上記のステートメントをToadで直接実行し、完全に正常にSQLiteテーブルを実行しています。
Nhibernate.Id 名前空間からの Command.ExecuteReader クラス (193 行目) の command.ExecuteReader ステートメントを使用して Nhibernate アセンブリを逆アセンブル (resharper を使用) すると、レコードが返されないため、この例外がスローされます。
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
...
...
...
}