These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Commit failure
PostPosted: Fri Dec 15, 2006 1:14 am 
Newbie

Joined: Fri Dec 15, 2006 12:46 am
Posts: 3
NHibernate 1.2.0

I have a [n:n] relation between two class and made a relation table in my db. In the relation table the indexes from table Family and Sector is combined primary key

When I commit a SaveOrUpdate between these classes, I get a "commit failed with SQL exception".

Code:
NHibernate: DELETE FROM SectorMucking WHERE FamilyIndex = @p0; @p0 = '2'
NHibernate: INSERT INTO SectorMucking (FamilyIndex, SectorIndex) VALUES (@p0, @p1); @p0 = '2', @p1 = '1'
06:11:33,703 ERROR AdoTransaction:181 - Commit failed
System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.
   at System.Data.SqlClient.SqlTransaction.ZombieCheck()
   at System.Data.SqlClient.SqlTransaction.Commit()
   at NHibernate.Transaction.AdoTransaction.Commit() in c:\net\nhibernate\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:
line 166
06:11:33,703 ERROR AdoTransaction:181 - Commit failed
System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.
   at System.Data.SqlClient.SqlTransaction.ZombieCheck()
   at System.Data.SqlClient.SqlTransaction.Commit()
   at NHibernate.Transaction.AdoTransaction.Commit() in c:\net\nhibernate\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:
line 166


But the relation is committed...... Any help?!!
Code:
<class name="Common.Gang.Family, Common" table="Family">
    <id name="Index" column="FamilyIndex" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>

<bag name="HasMuckedIn" cascade="all" lazy="true" table="SectorMucking">
      <key>
        <column name="FamilyIndex" not-null="true" />
      </key>
      <many-to-many class="Common.Gang.Item.Sector, Common">
        <column name="SectorIndex" not-null="true" />
      </many-to-many>
    </bag>
</class>


Code:
<class name="Common.Gang.Item.Sector, Common" table="Sector">

    <id name="Index" column="SectorIndex" type="Int32" unsaved-value="0">
      <generator class="native"/>
    </id>
</class>
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 2:34 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Apparently you are trying to commit a transaction twice, or commit it after a rollback.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 11:31 pm 
Newbie

Joined: Fri Dec 15, 2006 12:46 am
Posts: 3
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; }
        }
    }


Factory

Code:
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();
            }
        }


Activation

Code:
BankFactory factory = new BankFactory();


Logging

Code:
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 5:46 am 
Beginner
Beginner

Joined: Sat Sep 09, 2006 5:55 am
Posts: 23
It looks like you are building a new session factory for every database action...

This is probably not what you want to do, you typically only need one sessionfactory (for each database) for your entire application.

_________________
Cheers,

Guy Mahieu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.