• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with Hibernate transaction in CMT

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a secnario like this:

CMT with Hibernate
1. Insert a record into table1 with JXP
2. execute select query with Hibernate on table1 to fetch the record inserted in the above table.
3. Result: No records present in the table ------------> (1)
4. close the hibernate session/tx
Below is the code snippet:
CustomService(CMT) {
PartyRole (CMT) -> insert record
Hibernate -> select record
}


Only with Hibernate
1. Insert a record into table2 using session.save(obj)
2. execute select query on table2 to fetch the record inserted in the above table.
3. 1 record present in the table.-------------------- > (2)
4. commit/close the transaction
Below is the code snippet
create() method: Complete Hibernate
{
open session/transaction
insert record;
select record; -> able to fetch the record.
commit and close ;
}

With the above findings, For the first one....I understood that Hibernate is not identifying any db changes performed by CMT.
In the second example, insert and select done by hibernate. so i am able to fetch the records which is not committed.

Can you help, Is there any way to specify hibernate to make use of the CMT transaction. how it should identify the changes done by CMT.

In Hibernate code I have tried with openSession() as well as currentSession. but did not work.

Please help me in this.

-Kiran
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kiran,
Are you in the same transaction/connection? Even in the EJB world, there were problems if you committed something with EJB and tried to read it with JDBC.
 
kiran_kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is part of single CMT transaction.
 
kiran_kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally I got the answer for this problem.

We need to pass the data base connection object to the hibernate session. That means both CMT and hibernate should use the same connection object.

we have a method in SessionFactory.OpenSession(Connection conn)

it will make use of the existing connection, here we no need to use any transaction object again.

-Kiran
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are explicitly opening a session you will need to associate the connection yourself as you say, however if you just get the current session everything should just work (assuming you have correctly configured Hibernate to participate in CMT).
 
Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic