Save() is not generating any insert statements

127 views
Skip to first unread message

graffitiMSX

unread,
Oct 29, 2012, 3:02:33 PM10/29/12
to fluent-n...@googlegroups.com
Hi,
I am trying to save one entity to db using a Transaction,and all the selects are being executed normally (and logged in on NHibernate Profiler), but when I call Save(entity) the Insert is not being generated. My DB is Oracle 11g and the code/mapping follows:

Config:

DataAccess.Server = "...";
DataAccess.Username = "...";
DataAccess.Password = "...";
DataAccess.ServiceName = "XE";
DataAccess.Schema = "...";
DataAccess.Port = 1521;
DataAccess.DataBaseType = DatabaseTypeEnum.Oracle10g;

string connString = String.Format(
    "user id={0};password={1};data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={2})(PORT={3}))(CONNECT_DATA=(SERVICE_NAME={4})))",
    Username, Password, Server, Port, ServiceName);
 
_sessionFactory = Fluently.Configure()
    .Database(OracleClientConfiguration.Oracle10                        
         .ConnectionString(c => c.Is(connString))
        .ShowSql())
.ExposeConfiguration(c => c.SetProperty("generate_statistics""true"))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
    .BuildSessionFactory();

------------------------------------------------------
Mapping:

public RemitMap()
{
              Table("EI_REMIT");
              LazyLoad();
              Id(x => x.Id)
                .Column("ID")
                .CustomType("Int32")
                .Access.Property()
                .CustomSqlType("NUMBER")
                .Not.Nullable()
                .Precision(38)                
                .GeneratedBy.Sequence("EI_REMIT_ID_SEQ");
              Map(x => x.Sequence)    
                .Column("SEQUENCE")
                .CustomType("Int32")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("NUMBER")
                .Not.Nullable()
                .Precision(38);
              References(x => x.RemitStatus)
                .Class<RemitStatus>()
                .Access.Property()
                .Cascade.None()
                .LazyLoad()
                .Columns("EI_REMIT_STATUS_ID");
              References(x => x.Tag)
                .Class<Tag>()
                .Access.Property()
                .Cascade.None()
                .LazyLoad()
                .Columns("EI_TAG_ID");
        }
}
---------------------------------------------------------------------------
Entity:

public partial class Remit
{
 
        private Int32 _Id;
 
        private Int32 _Sequence;
 
        private RemitStatus _RemitStatus;
 
        private Tag _Tag;

        public virtual Int32 Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                this._Id = value;
            }
        }

        public virtual Int32 Sequence
        {
            get
            {
                return this._Sequence;
            }
            set
            {
                this._Sequence = value;
            }
        }

        public virtual RemitStatus RemitStatus
        {
            get
            {
                return this._RemitStatus;
            }
            set
            {
                this._RemitStatus = value;
            }
        }

        public virtual Tag Tag
        {
            get
            {
                return this._Tag;
            }
            set
            {
                this._Tag = value;
            }
        }
}
--------------------------------------------------------
Code:

Remit remit = new Remit();
remit.Tag = _tagDao.FindById<Tag>("Id", (Int32)_id);
remit.RemitStatus = _remitStatusDao.FindById<RemitStatus>("Id", (Int32)_remitStatus.Sent);
remit.Sequence = _sequence;
_remitDao.Save(remit);

--------------------------------------------------------

That´s all..
When the 2nd and 3rd lines are being processed, they appear on NHibernate Profiler, but the last line only generates the lines:

select EI_REMIT_ID_SEQ.nextval
from   dual

And nothing else...

Thanks for your help!

Rudolf.

Oskar Berggren

unread,
Oct 29, 2012, 3:46:47 PM10/29/12
to fluent-n...@googlegroups.com
http://www.tobinharris.com/2007/2/3/nhibernate-faq

/Oskar

2012/10/29 graffitiMSX <rudolf...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/vvbI4y2_v2wJ.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

Brandon Perry

unread,
Oct 29, 2012, 3:48:24 PM10/29/12
to fluent-n...@googlegroups.com
Ensure you are calling transaction.Commit();
> --
> You received this message because you are subscribed to the Google
> Groups "Fluent NHibernate" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fluent-nhibernate/-/vvbI4y2_v2wJ.
> To post to this group, send email to
> fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to fluent-nhibernate
> +unsub...@googlegroups.com.

graffitiMSX

unread,
Oct 30, 2012, 6:49:29 AM10/30/12
to fluent-n...@googlegroups.com, bperry....@gmail.com
That´s the strange thing. Here is the main transaction block of code:

using (var session = _session.SessionFactory.OpenSession())
{
using (var tx = _session.BeginTransaction())
{
try
{
// create the first entity
Remittance remittance = new Remittance();
(...)
_remittanceDao.Save(remittance);
(...)
// create a list with entities
List<TripSent> tripSentList = new List<TripSent>();
for (int i = 0; i < _sepTransactionFile.Details.Count; i++)
{
TripSent tripSent = new TripSent();
(...)
tripSentList.Add(tripSent);
}
// save the list
foreach (TripSent tripSent in tripSentList)
{
_tripSentDao.Save(tripSent);
}
// create final entity
TransactionFile transactionFile = new TransactionFile();
(...)
_transactionFileDao.Save(transactionFile);
// commit (and automatically flush)
tx.Commit();
}
catch
{
// problem? Rollback
tx.Rollback();
}
}
}

I create the entities, call SAVE() for each and at the end there is a Commit() to flush all data do DB. But no INSERT is been generated.

Together with this message I put the results for NHibernate Profiler.

Thanks,
Rudolf
test_fluent.html

Oskar Berggren

unread,
Oct 30, 2012, 7:00:11 AM10/30/12
to fluent-n...@googlegroups.com
That catch clause will in effect hide all exceptions, which is an excellect way to create a mysterious system. :) Maybe your problem is there.

Also, the transaction will automatically rollback on dispose if not committed, so the try-catch can be removed entirely.

/Oskar


2012/10/30 graffitiMSX <rudolf...@gmail.com>
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/uprs0WrkolIJ.

To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.

graffitiMSX

unread,
Oct 30, 2012, 7:38:30 AM10/30/12
to fluent-n...@googlegroups.com
As I was debugging, I saw all the exceptions generated (but in this case all went normal). And I omitted here, but I set some flags within the Catch statement to track errors.

With NHibernate Profiler I detected a error not in this part of code, but in the DAOs used to save the entities. When I changed all the _xxxDao.Save(entity) by _session.Save(entity) all was solved :)

Many thanks to all of you that helped me to see better the problem.

Rudolf
Reply all
Reply to author
Forward
0 new messages