Apperently everything is done twice.....
Entity
Code:
public class GenerelAccount
{
protected int index;
protected decimal balance;
protected DateTime updated;
protected DateTime created;
public virtual int Index
{
get { return index; }
set { index = value; }
}
public virtual decimal Balance
{
get { return balance; }
set { balance = value; }
}
public virtual DateTime Updated
{
get { return updated; }
set { updated = value; }
}
public virtual DateTime Created
{
get { return created; }
set { created = value; }
}
}
Code:
public class BankAccount : GenerelAccount
{
private int tick;
private int addInterest;
public virtual int Tick
{
get { return tick; }
set { tick = value; }
}
public virtual int AddInterest
{
get { return addInterest; }
set { addInterest = value; }
}
}
FactoryCode:
public class FactoryInit
{
protected Configuration config;
public FactoryInit()
{
try
{
config = new Configuration();
config.AddAssembly("Server");
}
catch (Exception ex)
{
throw ex;
}
}
}
Code:
public BankFactory() : base()
{
}
public void Set(BankAccount account)
{
ISessionFactory factory = null;
ISession session = null;
ITransaction trx = null;
try
{
factory = base.config.BuildSessionFactory();
session = factory.OpenSession();
if (!session.IsConnected)
{
session.Reconnect();
}
trx = session.BeginTransaction();
session.Save(account);
trx.Commit();
}
catch (Exception ex)
{
trx.Rollback();
throw ex;
}
finally
{
session.Close();
}
}
public BankAccount Get(int index)
{
ISessionFactory factory = null;
ISession session = null;
ITransaction trx = null;
BankAccount account = null;
try
{
factory = base.config.BuildSessionFactory();
session = factory.OpenSession();
if (!session.IsConnected)
{
session.Reconnect();
}
trx = session.BeginTransaction();
account = ((BankAccount)session.CreateCriteria(typeof(BankAccount))
.Add(Expression.Eq("Index", index))
.List()[0]);
return account;
}
catch (Exception ex)
{
trx.Rollback();
throw ex;
}
finally
{
session.Close();
}
}
ActivationCode:
BankFactory factory = new BankFactory();
LoggingCode:
04:30:21,562 INFO Environment:151 - NHibernate 1.2.0.2002 (1.2.0.2002)
04:30:21,562 INFO Environment:151 - NHibernate 1.2.0.2002 (1.2.0.2002)
04:30:21,609 INFO Environment:257 - Bytecode provider name : lcg
04:30:21,609 INFO Environment:257 - Bytecode provider name : lcg
04:30:21,609 INFO Environment:164 - Using reflection optimizer
04:30:21,609 INFO Environment:164 - Using reflection optimizer
04:30:21,609 INFO Configuration:565 - Searching for mapped documents in assembly: Server
04:30:21,609 INFO Configuration:565 - Searching for mapped documents in assembly: Server
04:30:21,609 INFO Configuration:633 - Found mapping document in assembly: Server.Data.Mapping.GenerelAccount.hbm.xml
04:30:21,609 INFO Configuration:633 - Found mapping document in assembly: Server.Data.Mapping.GenerelAccount.hbm.xml
04:30:21,609 INFO Configuration:504 - Mapping resource: Server.Data.Mapping.GenerelAccount.hbm.xml
04:30:21,609 INFO Configuration:504 - Mapping resource: Server.Data.Mapping.GenerelAccount.hbm.xml
04:30:21,687 INFO Dialect:67 - Using dialect: NHibernate.Dialect.MsSql2005Dialect
04:30:21,687 INFO Dialect:67 - Using dialect: NHibernate.Dialect.MsSql2005Dialect
04:30:21,750 INFO HbmBinder:309 - Mapping class: Common.Bank.GenerelAccount -> Account
04:30:21,750 INFO HbmBinder:309 - Mapping class: Common.Bank.GenerelAccount -> Account
04:30:21,796 DEBUG HbmBinder:614 - Mapped property: Index -> AccountIndex, type: Int32
04:30:21,796 DEBUG HbmBinder:614 - Mapped property: Index -> AccountIndex, type: Int32
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Balance -> Balance, type: Decimal
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Balance -> Balance, type: Decimal
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Updated -> Updated, type: DateTime
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Updated -> Updated, type: DateTime
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Created -> Created, type: DateTime
04:30:21,812 DEBUG HbmBinder:614 - Mapped property: Created -> Created, type: DateTime
04:30:21,828 INFO HbmBinder:242 - Mapping subclass: Common.Bank.BankAccount -> Account
04:30:21,828 INFO HbmBinder:242 - Mapping subclass: Common.Bank.BankAccount -> Account
04:30:21,828 DEBUG HbmBinder:614 - Mapped property: Tick -> Tick, type: Int32
04:30:21,828 DEBUG HbmBinder:614 - Mapped property: Tick -> Tick, type: Int32
04:30:21,843 DEBUG HbmBinder:614 - Mapped property: AddInterest -> AddInterest, type: Int32
04:30:21,843 DEBUG HbmBinder:614 - Mapped property: AddInterest -> AddInterest, type: Int32