Web application and multiple sessions

I am working on a web application that runs under Visual Studio 2005, language C#. I designed with Visual Paradigm the classes diagram and automatically generated the database and code with the VP tools.

The Perstent API type I used for code generation is “Static Methods”, I think is the most simple and ok for me.

I created a class called dao.cs so it contains every access to the database and connections. It looks like this:

public class dao
private PersistentManager persistenceManager = HMIPersistentManager.Instance();

private static dao instance = null;

private dao()

public static dao getInstance()
	if (instance == null)
		instance = new dao();
	return instance;

     public Recipe getRecipeByID(int id)
	PersistentTransaction t = this.persistenceManager.GetSession().BeginTransaction();

	Recipe a = Recipe.LoadRecipeByORMID(id);

	t.Commit(); // <<-- exception here: already opened conexion or ID already in use....
	return a;

    /* more methods... */


The problem is, when executing the project, sometimes it throws an exception on the “t.Commit();” line. I would like to implement the best way for a web application: multiple users accessing the database, and everything running fine.

Do I need to use a lock like:
PersistentManager.instance().getSession().lock(obj, LockMode.NONE);

Where do I put it? Which lockmode choose?

Thanks in advance

Hi hectoret,

When running in web environment, please make sure have

  1. close session before return values

  2. running thread based session


Hope this helps.

Best regards,