| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : admin
Title :
SessionFactory
Description :
Question on Session Factory Creation More...
|
Written By : Amit
Title :
Interview Questions
Description :
On Hibernate More...
|
Written By : Amit
Title :
mapping class hierarchy table per subclass
Description :
Example More...
|
Written By : Amit
Title :
ways create Hibernate SessionFactory
Description :
Example More...
|
Written By : Amit
Title :
Spring Hibernate Integration example
Description :
Example More...
|
| Tags/Keywords : Hibernate Transaction, JTA with Hibernate, Session, CurrentSession, Transaction, JTA Example Code, Example, Tutorial, Article Author : guddu Date (Year/Month/Date): 2010-06-20
Example code working with Container managed transaction and Hibernate Session | |
Please be informed that NONE of the design/code/matter from this page is claiming to be some
sort of best practice and we DO NOT expect any of our visitor/reader of this page to assume
this as some sort of best practice for any context and should not be using this as it is
without appropriate evaluation.
This page intends only to provide bits and pieces of known ways for doing some sort of example
and may not be fit for any other purpose.
In spite of all precautions taken to provide accurate and avoid any typo in these pages,
there might be some issues like grammatical mistakes and typo being observed in these pages,
We extend our sincerest apologies for the same.
Using JTA transaction with Hibernate Session for carrying out
multiple database operations as an Unit of Work.
This means either all the database operations do succeed,
or else all changes gets roll backed.
I shall be using the same old example, as to transfer some
amount from one account to another account, whereby some
amount is being subtracted from one account and added onto
balance of another account. In this case it is obvious that
either both debit and credit operations should succeed, or else
all the changes made should be undone.
I shall be starting with a similar example being shown on this
site some time back, one can refer it HERE.
In this example, there is a TestClient, a testing harness code.
This test program is calling a sesson facade or session bean,
and this session bean is using a hypothetical service named as
AccountService. This AccountService is using AccountDAO in order to
use Hibernate specific DAO/Hibernate Session instance for doing
all sorts of database operation, such as read, save, update, delete
etc.
One interesting fact about this example is that, I am using
Application server container managed transaction for these
multiple operations, those are being tagged as a single unit
of work. Sounds interesting !! Let's review code for this example.
Most of the source files are used as it is, apart from some
of the files such as Account class, its related HBM mapping
XML file, related ejb-jar.xml file, and corresponding database
table column being added, in order to add another attribute
for storing amount balance.
There are few more service methods are added, such as transferAmount
fetch account object etc.
So the database (I have used MySQL version 5.0), table creation script
looks like as follows:
CREATE TABLE account_info (
account_number varchar(100) NOT NULL,
holder_name varchar(100) DEFAULT NULL,
account_type varchar(100) DEFAULT NULL,
account_balance decimal(20,2) DEFAULT NULL,
account_active_status int(1) DEFAULT NULL,
PRIMARY KEY (account_number)
)
|
On execution of this example, following is snippet/fraction of
console output that is showing that transfer amount operations
are using the same JTA transaction, as shown in the following
output:
Starting with Transaction :org.hibernate.transaction.JTATransaction@9f33d
Hibernate: select account0_.account_number as account1_59_0_, account0_.hol
Hibernate: select account0_.account_number as account1_59_0_, account0_.hol
Commiting with Transaction :org.hibernate.transaction.JTATransaction@9f33d
|
Most of the other files can be viewed after log in or register
with this web site, and only in the following section of the page.
Login / Register
|
|
|
Commented By -> Suresh Yadav | Thanks for this helpful article,
Can you please help me with configuration setting
for Transaction, TransactionFactory and TransactionManagerLookUp
class files for JONAS application server?
Hope to hear from you soon.. |
| | |
Commented By -> guddu | Hi Suresh,
Please go through class files under package
org.hibernate.transaction for all the available
transaction manager lookup classes for various
application servers including JOnAS application
server.
I looked at javadoc api for Hibernate version 3.2
and found one class files as
org.hibernate.transaction.JOnASTransactionManagerLookup
I think you should be able to try with this
and if it works please update us by writing
a small note on this page.
Thanks anyways. |
| |
|
|
| Home >>> Hibernate Tutorial >>> Hibernate Session With JTA Transaction >>> Example code discussed |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
| |  |
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners
This web site's Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
or imply reliability of these example source code or programs.
By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
at contact.
|  |
|
|
|
|
|