[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - problem in concurrent access of database
Heilien
do-not-reply at jboss.com
Wed Apr 29 22:50:37 EDT 2009
good day all,
I am running 2 program on separate JVM on the same server. both use hibernate to access the database. It seems that program1 always wait for program2 's database access complete and continue, or vice versa. It looks like sequential execution.
I guess it's something wrong with my code. anyone can help me with it?
below is the hibernate util class
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static SessionFactory sessionFactory;
|
| static {
| try {
| sessionFactory = new Configuration().configure().buildSessionFactory();
| } catch (Throwable ex) {
| throw new RuntimeException (ex);
| }
| }
|
| public static SessionFactory getSessionFactory() {
| return sessionFactory;
| }
|
| }
every method i access the database i will use the following pattern to get session and commit
public static ArticleType createArticleType(String description) {
| ArticleType ArticleType = new ArticleType();
| ArticleType.setDescription(description);
| Session session = HibernateUtil.getSessionFactory().getCurrentSession();
| session.beginTransaction();
| session.save(ArticleType);
| session.getTransaction().commit();
| return ArticleType;
| }
I am wondering should I open and close session for every call to the database, to prevent the blocking of other process.
thanks in advance
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4227680#4227680
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4227680
More information about the jboss-user
mailing list