Hibernate version:
1.0.2
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="RecEngineLib.Domain.RuleSets.RuleSetInvocation, RecEngineLib" table="RuleSetInvocation" >
<id name="ID" column="RuleSetInvocationID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="RuleSetName" />
<property name="RuleSetVersion" />
<property name="Timestamp" column="CreateDate"/>
<set name="Facts">
<key column="RuleSetInvocationID"/>
<one-to-many class="RecEngineLib.Domain.RuleSets.RecEngineFact, RecEngineLib"/>
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="RecEngineLib.Domain.RuleSets.RecEngineFact, RecEngineLib" table="EngineFact" >
<id name="ID" column="EngineFactID" unsaved-value="0">
<generator class="identity" />
</id>
<discriminator column="Type"/>
<property name="Label" />
<property name="Name" />
<primitive-array name="Values" table="EngineFactValue">
<key column="EngineFactID"/>
<index column="EngineFactValueID"/>
<element column="value" type="String(255)" />
</primitive-array>
</class>
</hibernate-mapping>
Code :Code:
using System;
using System.Collections.Generic;
using NHibernate.Generics;
namespace RecEngineLib.Domain.RuleSets
{
public class RuleSetInvocation : DomainObject<int>
{
#region Private Members
private string m_ruleSetName;
private int m_ruleSetVersion;
private DateTime m_timestamp = new DateTime();
// NHibernate.Generics members must be named in the following format: _camelCase
private IList<RecEngineFact> _facts = new EntityList<RecEngineFact>();
#endregion
#region Properties
public string RuleSetName
{
get { return m_ruleSetName; }
set { m_ruleSetName = value; }
}
public int RuleSetVersion
{
get { return m_ruleSetVersion; }
set { m_ruleSetVersion = value; }
}
public IList<RecEngineFact> Facts
{
get { return _facts; }
}
public DateTime Timestamp
{
get { return m_timestamp; }
set { m_timestamp = value; }
}
#endregion
#region Constructors
public RuleSetInvocation() { }
public RuleSetInvocation(IRuleSet p_ruleSet, RecEngineFact[] p_facts)
{
this.m_ruleSetName = p_ruleSet.Name;
this.m_ruleSetVersion = p_ruleSet.Version;
foreach (RecEngineFact l_fact in p_facts)
this._facts.Add(l_fact);
}
#endregion
}
}
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using org.nxbre.ie;
using org.nxbre.ie.rule;
using org.nxbre.ie.predicates;
namespace RecEngineLib.Domain.RuleSets
{
[Serializable]
public class RecEngineFact
{
private string m_relationName, m_label;
private string[] m_values;
private int m_id;
public RecEngineFact()
{
}
public RecEngineFact(string p_label, string p_relationName, string[] p_value)
{
this.m_label = p_label;
this.m_relationName = p_relationName;
this.m_values = p_value;
}
public string Name
{
get { return m_relationName; }
set { m_relationName = value; }
}
public int ID
{
get { return m_id; }
set { m_id = value; }
}
public string Label
{
get { return m_label; }
set { m_label = value; }
}
public string[] Values
{
get { return m_values; }
set { m_values = value; }
}
public Fact ToNxBREFact()
{
IPredicate[] l_predicates = new Individual[this.m_values.Length];
for (int i = 0; i < this.m_values.Length; i++)
{
float l_valueAsNumber;
if (float.TryParse(this.m_values[i], out l_valueAsNumber))
{
l_predicates[i] = new Individual(l_valueAsNumber);
}
else
{
l_predicates[i] = new Individual(this.m_values[i]);
}
}
return new Fact(this.Label, this.Name, l_predicates);
}
public static RecEngineFact FromNxBREFact(Fact p_fact)
{
string[] l_values = new string[p_fact.PredicateValues.Length];
for (int i = 0; i < p_fact.PredicateValues.Length; i++)
l_values[i] = p_fact.PredicateValues[i].ToString();
return new RecEngineFact(p_fact.Label, p_fact.Type, l_values);
}
public override string ToString()
{
string l_result = "";
if (this.Label != null && !this.Label.Equals(""))
l_result += this.Label + ": ";
l_result += this.Name;
l_result += "(";
bool l_first = true;
foreach (string l_value in this.Values)
{
if (l_first)
l_first = false;
else
l_result += ",";
l_result += l_value;
}
l_result += ")";
return l_result;
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
if (!(obj is RecEngineFact))
return false;
RecEngineFact l_fact = (RecEngineFact)obj;
if (!l_fact.Name.Equals(this.Name))
return false;
if (l_fact.Values.Length != this.Values.Length)
return false;
for (int i = 0; i < this.Values.Length; i++)
{
string l_value1 = this.Values[i], l_value2 = l_fact.Values[i];
double l_numValue1, l_numValue2;
if (double.TryParse(l_value1, out l_numValue1) && double.TryParse(l_value2, out l_numValue2))
{
// Try to compare them as numbers if they are both valid numbers.
if (l_numValue1 != l_numValue2)
return false;
}
else
{
// Otherwise just compare them as strings.
if (!this.Values[i].Equals(l_fact.Values[i]))
return false;
}
}
return true;
}
}
}
Full stack trace of any exception that occurs:Code:
[AssertionFailure]: null id in entry (don't flush the Session after an exception
occurs)
at NHibernate.Impl.SessionImpl.CheckId(Object obj, IClassPersister persister,
Object id)
at NHibernate.Impl.SessionImpl.FlushEntity(Object obj, EntityEntry entry)
at NHibernate.Impl.SessionImpl.FlushEntities()
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at RecEngineLib.DataImpl.NHibernateSessionManager.CommitTransaction() in C:\R
ecEngineDotNet\RecEngineLib\DataImpl\NHibernateSessionManager.cs:line 148
at NHibernateSessionModule.CommitAndCloseSession(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplicati
on.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& compl
etedSynchronously)
-->
--.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie
ntMessage message, WebResponse response, Stream responseStream, Boolean asyncCal
l)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN
ame, Object[] parameters)
at RecEngineTest.RecEngineServer.CIQRecEngineService.ApplyRules(String p_rule
SetName, Int32 p_ruleSetVersion, RecEngineFact[] p_facts) in C:\RecEngineDotNet\
recenginetest\Web References\RecEngineServer\Reference.cs:line 108
at RecEngineTest.Program.Main(String[] args) in C:\RecEngineDotNet\recenginet
est\Program.cs:line 40
Name and version of the database you are using:SQL Server 2000 SP4
Table Schema:Code:
CREATE TABLE RuleSetInvocation(
RuleSetInvocationID INT IDENTITY(1,1) NOT NULL,
RuleSetName VARCHAR(255) NOT NULL,
RuleSetVersion INT NOT NULL,
CreateDate DATETIME NOT NULL)
go
CREATE TABLE EngineFact(
EngineFactID INT IDENTITY(1,1) NOT NULL,
RuleSetInvocationID INT NOT NULL,
Type INT NOT NULL,
Label VARCHAR(255) NOT NULL,
Name VARCHAR(255) NOT NULL)
CREATE TABLE EngineFactValue(
EngineFactValueID INT NOT NULL,
EngineFactID INT NOT NULL,
Value VARCHAR(255) NOT NULL)
Debug level Hibernate log excerpt:Code:
14:57:01.132 [3608] DEBUG NHibernate.Transaction.AdoTransaction - commit
14:57:01.132 [3608] DEBUG NHibernate.Impl.SessionImpl - flushing session
14:57:01.132 [3608] DEBUG NHibernate.Impl.SessionImpl - Flushing entities and processing referenced collections
14:57:01.132 [3608] ERROR NHibernate.AssertionFailure - An AssertionFailure occured - this may indicate a bug in NHibernate
NHibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)
14:57:01.132 [3608] DEBUG NHibernate.Impl.SessionImpl - closing session
14:57:01.132 [3608] DEBUG NHibernate.Impl.SessionImpl - disconnecting session
14:57:01.148 [3608] DEBUG NHibernate.Connection.ConnectionProvider - Closing connection
So I am not sure what is going on, newbie here... I've been struggling for a few days on my first Nhibernate project
Last point, I have a "Type" for descriminator that I don't use yet,
it will be to have 2x _facts (InputFacts and OutputFact) but I don't know yet how to do this.
Thanks!
Christian