This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with Hibernate transaction in CMT

 
kiran_kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

It is part of single CMT transaction.
 
kiran_kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic