-->
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.  [ 5 posts ] 
Author Message
 Post subject: [Heavy client] How to use exactly one database connection
PostPosted: Tue Feb 27, 2007 4:59 am 
Newbie

Joined: Fri Feb 23, 2007 12:05 pm
Posts: 6
Hello,

I'm currently working on a client / server project in .Net, and we need to make sure that each client application will use 1 and only 1 connection to the database.

Unfortunately, we saw recently that when a new object need to be inserted into the database, an extra database connection is created by Nhibernate. With deeper investigations, it seems that it happens when NHibernate generate the object key, which is configured to use the hilo algorithm.

My questions are :

- can I force NHibernate to use only one single connection, without changing the generator algorithm ? (with a kind of session factory parameter maybe ?)
- if no, and if I change the generator algorithm, can I avoid this extra connection to be created, or are there other cases where connections will be created anyway ?

Until now I've not been able to find documentation on that topic. I hope somebody can help me on this one.

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 5:14 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can avoid it by changing the id generator, but a separate connection was there for a reason - the generator has to do some work outside current transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 6:30 am 
Newbie

Joined: Fri Feb 23, 2007 12:05 pm
Posts: 6
Thanks a lot for your fast answer, Sergei !

So you mean that if I change all my generated IDs from *hilo* to *guid*, no extra database connection should be created by NHibernate anymore (knowing that in the way I made my code, the application always rely on the same ISession) ?

BR,
Mikvix


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 7:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, guid is about the nicest identifier generator there is, from NHibernate's point of view.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 10:14 am 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
You could event use guid.comb as a method to avoid fragmentation of indexes.

Technical background:
http://www.informit.com/articles/articl ... 25862&rl=1

Usage with NH:
http://codebetter.com/blogs/jeffrey.pal ... 48448.aspx

_________________
Dragos


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