database java.lang.IllegalStateException: Session/EntityManager is closed & java.lang.IllegalStateEx

5,238 views
Skip to first unread message

netma...@gmail.com

unread,
Oct 18, 2017, 3:42:29 AM10/18/17
to jPOS Users
Hi,

We have couple of participants in transaction manager, each participants do DB.open, some db operation and DB.close. We have configured 2 transaction manager, one for request processing and one for response processing. We have also provided hibernate.c3p0.min_size=5, hibernate.c3p0.max_size=10,<property name="sessions" value="10"/>,    <property name="max-sessions" value="10" /> .

We received the  "database java.lang.IllegalStateException: Session/EntityManager is closed in one transaction manager &  java.lang.IllegalStateException: Transaction already active in another transaction manager".


Though we have configured multiple sessions in transaction manager and provided connection pool.

Please guide.


Thanks,
Net

chhil

unread,
Oct 18, 2017, 10:23:28 AM10/18/17
to jpos-...@googlegroups.com
You should read up on hibernate and updating the db from different threads.



-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/ed25462a-fbb7-468c-a11b-36b7bca394dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

netma...@gmail.com

unread,
Oct 23, 2017, 3:51:54 AM10/23/17
to jPOS Users
Hi,

Does this mean that 2 different transaction manager use the one db connection for 2 different threads? as I have already provided c3p0 connection pool parameter, so it should use different connection.


Thanks.



On Wednesday, October 18, 2017 at 7:53:28 PM UTC+5:30, chhil wrote:
You should read up on hibernate and updating the db from different threads.



-chhil
On Oct 18, 2017 1:12 PM, <netma...@gmail.com> wrote:
Hi,

We have couple of participants in transaction manager, each participants do DB.open, some db operation and DB.close. We have configured 2 transaction manager, one for request processing and one for response processing. We have also provided hibernate.c3p0.min_size=5, hibernate.c3p0.max_size=10,<property name="sessions" value="10"/>,    <property name="max-sessions" value="10" /> .

We received the  "database java.lang.IllegalStateException: Session/EntityManager is closed in one transaction manager &  java.lang.IllegalStateException: Transaction already active in another transaction manager".


Though we have configured multiple sessions in transaction manager and provided connection pool.

Please guide.


Thanks,
Net

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Alejandro Revilla

unread,
Oct 24, 2017, 1:20:13 PM10/24/17
to jPOS Users

No, that’s not how it works. If you’re using the dbsupport module, which in turns uses Hibernate, and C3P0 under the hood, the org.jpos.ee.DB class takes care of getting a connection from the pool, when required.


netma...@gmail.com

unread,
Oct 25, 2017, 3:49:19 AM10/25/17
to jPOS Users
Hi Alejandro,

We are using the same DB class. When we do DB.open() it returns the session object. Do you want to say that this session object is always return from connection pool.

If I see the code for open method, it is coming from sessionFactory only in case of session is null otherwise it returns the same session object.

It will be good if you explain more detail of it, to understand the connection pool or session.

Also in our case if 2 different connections are getting used in 2 different transactionmanager, we should not get those exception.


Thanks,
prd

Alejandro Revilla

unread,
Oct 30, 2017, 1:26:34 PM10/30/17
to jPOS Users
Every thread requiring access to the database should create a new DB object (which is an inexpensive operation). Then you call open/commit/close on that thread.

Every time you do that, the system gives you a new Hibernate session, with its underlying JDBC session taken from the pool.

The DB class implements Closeable, so you can use the try-with-resources variant, i.e:

   try (DB db = new DB()) {
       ...
       ...
   }

Hope this helps.




--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.

netma...@gmail.com

unread,
Nov 9, 2017, 2:40:06 AM11/9/17
to jPOS Users
Hi Alejandro,

You are saying that for every new transaction received in transaction manager, should always create new DB() instance, instead of creating one singleton object of DB and just used db.session()


Thanks,
prd


To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Alejandro Revilla

unread,
Nov 9, 2017, 1:49:42 PM11/9/17
to jPOS Users
Yes. Creating a new DB() is a very cheap operation. Under the hood, it uses a Hibernate's C3P0's JDBC pool whenever you call DB.open()


netma...@gmail.com

unread,
Nov 10, 2017, 8:18:45 AM11/10/17
to jPOS Users
Thanks a lot Alejandro. We did the same, till now it is working fine.


Thanks,
prd
Reply all
Reply to author
Forward
0 new messages