My project connects to a database using hibernate, getting connections from a connection pool on JBoss. I want to replace some of the reads/writes to tables with publish/consume from queues. I built a working example that uses OracleAQ, however, I am connecting to the DB using:
AQjmsFactory.getQueueConnectionFactory
followed by createQueueConnection
,
then using createQueueSession
to get a (JMS) QueueSession
on which I can call createProducer
and createConsumer
.
So I know how to do what I want using a jms.QueueSession
. But using hibernate, I get a hibernate.session
, which doesn't have those methods.
I don't want to open a new connection every time I perform an action on a queue - which is what I am doing now in my working example. Is there a way to perform queue operations from a hibernate.session
? Only with SQL queries?
I think you're confusing a JMS (message queue) session with a Hibernate (database) session. The Hibernate framework doesn't have any overlap with JMS, so it can't be used to do both things.
You'll need 2 different sessions for this to work:
org.hibernate.Session
) for DB workjavax.jms.Session
) to to JMS/queue workDepending on your use case, you may also want an XA transaction manager to do a proper two-phase commit across both sessions and maintain transactional integrity.