-->
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.  [ 7 posts ] 
Author Message
 Post subject: Transactions & DataBinding
PostPosted: Sun Oct 29, 2006 10:43 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Hibernate version:NHibernate V1.0.2

Name and version of the database you are using:SLQSERVEREXPRESS 2005

Dear members,

I have to questions in mind, which i can't find an exact answer for .
1) Why do i need transaction ? for atomicity , isn't so ?
While i'm creating my Basic DLL Class, in the Select statement,
session.Load(typeog(..)..) or session.Get(...), i'm using a transaction ...

example :

public IList GetByType(Type type)
{
IList items = null;
ITransaction tx = null;

try
{
tx = m_session.BeginTransaction();

items = m_session.CreateCriteria(type).List();

tx.Commit();

return items;
}
catch (Exception ex)
{
if (tx != null) tx.Rollback();

throw ex;
}
}

Why do i need transaction when there is only one instruction and this instruction (query) reads from the DB .. ?
Logically, I suppose we should set the transaction on a higher layer ( Facade ) on delete and update operations .. but that would ruin the architecture model and the separation layes, isn't so ?
What is the solution?

2) I'm trying to execute 2 select, cause in my gridview i'm using 2 dropdownlists, 1 for the GridView ObjectDataSource and the other for the 2nd ObjectDataSource for the DropDowList ..

These 2 object datasources call for the m_session.Find(HQL), in the dataaccess layer (DLL) , the problem is that i'm getting an exception raised:

SQLSERVER does not permit PARALLEL Transaction


I've noticed that No exception is raised when i'm using m_session.Find() and an m_session.Load(...,...) function so
the session.Find() is such as Connected Mode !!
is that true ?
What shall i do in order to execute 2 Select functions using m_session.Find(hql), shall i remove the transaction on the Select Functions ?
Any suggestions ..

Regards,
Jojo Rico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 4:57 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
To answer your first question about using transactions, they're only needed if you make any changes to persistent objects.

If an object has been saved or updated to a Session or an object has been loaded from the DB into a Session and it's state changed the appropriate SQL INSERT, UPDATE or DELETE statements will be issued to the DB when the Session is flushed to persist the changes.

If you're only loading the object and are sure that the object will never be updated then a transaction isn't really necessary - but beware; it's important to note that a single object may span multiple tables in the DB, so if it's state is changed then multiple SQL UPDATE statements may be issued to update that one object. If you don't have a transaction in place and something fails in that process you could end up with garbage in your DB that you didn't expect, so transactions are pretty important, even if you're only performing actions on a single object.

I've found that using the TransactionScope object from the System.Transactions namespace works well for allowing you to use transactions from higher layers while still allowing you to use them in your lower layers but you will take a performance hit if you're not using SQL Server 2005 because other database connectors require the use of the Distributed Transaction Coordinator (DTC)...I'm not aware of any other database connector that supports promotable transactions at this stage.

I can't speak to your second question, so I'll have to leave it to someone else to answer.

Symon.


Top
 Profile  
 
 Post subject: Transactions tx & DataBinding
PostPosted: Mon Oct 30, 2006 2:06 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
mmm , quite interesting Symon.
Thank you for the reply, but it seems that you didn't exactly get my question .. so i'm gonna

In my base Class ( my class in the DataAccess Layer DLL), i implemented functions in order to use them in the Facade Layer, these functions include :

GetObjects , Save, GetBYPropertyValue ...

example :
public IList GetByType(Type type)
{
IList items = null;
ITransaction tx = null;

try
{
tx = m_session.BeginTransaction();

items = m_session.CreateCriteria(type).List();

tx.Commit();

return items;
}
catch (Exception ex)
{
if (tx != null) tx.Rollback();

throw ex;
}
}
So in this example, i'm getting a specific object from the Database, why do i need transaction here ? I might think that i don't need transaction for the following reasons:
1) That's a read from the database .
2) Between the tx opening and close blocks, i have one instruction that uses the database, not in the case of where i have to delete multiple kind of objects in the db at the same time (for example withdrawing money from an account to add it to another ) ..
3) If i used transaction in Facade layer, that would ruin the architecture i'm using , and the separation between layers . isn't so ?

4) I'm using 2 Object Data Sources in the Presentation Layer, 1 Object Data Source for the GridView COntrol and 1 Object Data Source for the Details View Control ( The same case is applied if i'm using the same Object Data Source for the GridView Control and the Details View Control).
I'm using the Details View to insert 1 Object in the Database, when i'm trying to do so (click on the insert in order to add the object) i'm getting this :
SQLSERVER Does not support Parallel Transactions ?

in my Select Method (for the GridView) i'm using this function :

public IList GetByType(Type type)
{
IList items = null;
ITransaction tx = null;

try
{
tx = m_session.BeginTransaction();

items = m_session.CreateCriteria(type).List();

tx.Commit();

return items;
}
catch (Exception ex)
{
if (tx != null) tx.Rollback();

throw ex;
}
}

in the insert function, i'm using this :

public void UPDATE_Category(int Id, string Cat, bool Status, int CatHasParentID)
{
Category myCat = dbManager.GetCategory(Id);
myCat.Cat = Cat;
myCat.Status = Status;

// Attention , we may need to empty the classes anbd the professors collections
// and to Update them Then update the Department class

/// Attention
if (CatHasParentID != 0)
{
Category CatLoaded = dbManager.GetCategory(CatHasParentID);
myCat.cathasparent = CatLoaded;
}
else
myCat.cathasparent = null;

dbManager.SaveCategory(myCat);
}

where dbManager.SaveCategory(myCat); calls :

public virtual void Save(object item, bool pointlessParameter)
{
ITransaction tx = null;

try
{
tx = m_session.BeginTransaction();

m_session.SaveOrUpdate(item);

tx.Commit();
}
catch (Exception ex)
{
if (tx != null) tx.Rollback();

throw ex;
}
}

What should i do to prevent parallel transactions ?
Any suggestions ?

Regards,
Jojo

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: Transaction tx & DataBinding
PostPosted: Tue Oct 31, 2006 2:37 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Let me Clarify the idea ...
All i want to do is Databind my hql on gridview !

my hql is written by using session.find("Select new Test(...,...) from ...")..
When i'm trying to use Gridview and a DetailsView, each of them having a different Object DataSource ( datasources), i'm getting :
Parallel Transaction is not supported on SQLSERVEREXPRESS 2005 ...

My purpose is to be able to :
1) Get an Ilist of objects having using queries ..
2) Databind these Collection of objects ( 2 or more) withoout having the error
Parallel Transaction is not supported on SQLSERVEREXPRESS 2005 ...

The solution may be related to the Transactions i'm using or maybe related to the session.find("Select ..."), maybe i can use something elses session.anymethod() to get an Ilist of objects ??

That should be a common problem ... although i searched the Forum but i couldn't finnd anything related to Parallel Transaction, ..

Any suggestions ?

Regards,
Jojo

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: Re: Transaction tx & DataBinding
PostPosted: Tue Oct 31, 2006 5:38 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jojorico wrote:
That should be a common problem ... although i searched the Forum but i couldn't finnd anything related to Parallel Transaction, ..

Sounds like You are starting a transaction while the previous one is not yet commited or rolled back (inside one session).

Why or how it happens is hard to tell. Full exception stack might help.

Anyway, the transaction is supposed to group several actions together, so "GetList()" is not the most appropriate place to start one.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Transactions & Databinding
PostPosted: Tue Oct 31, 2006 5:32 pm 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear Gert
I've solved the Parallel Transaction problem .
It had to do with the Rad control (Gridview). .. that's what i concluded .
Thanks for your reply..
Do u have answers for the other asked questions ?

Regards,
JojoRico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: Re: Transactions & Databinding
PostPosted: Wed Nov 01, 2006 3:23 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jojorico wrote:
Do u have answers for the other asked questions ?

Whichc ones do You mean?

As in my previous post, the transaction must group together logical set of actions, so the DAL is not right place to start one or commit one. I personally use Command pattern, but there are many possible solutions.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.