You can create a transaction around your code, either programatically (by manually writing transaction code) of declaratively.
Programatically, it means that you create a transaction with code( begin, commit, etc ) on each database interaction.
Code:
Transaction trx=session. ...
trx.begin....
[your persistence code here]
trx.commit();
}catch(...
trx.rollback()
"Declaratively", means that you are using some sort of "managed environment" (such as Spring) that takes care, mainly through configuration external to the code itself, of creating transactions where necessary.
(BTW, if you want the simplest example on how to integrate Hibernate with Spring, go here:
http://hibernar.org/articulos_en/spring ... xample.php
)
Annotations are one of the tools used by managed environments such as Spring to declaratively create transactions as needed. It is the most modern and easy strategy (shown in my article).
Previous declarative strategies to produce transactions made a more low-leve use of AOP (aspect oriented programming) or "Transaction Proxies" declared in your application context wrapping your business objects.
I don't know what the nature of your application is.
If it is a small, trivial application, you can write the transaction code programmatically (by hand).
If it is a web application, use Spring for creatig transactions declaratively, and remove most (or all) the explicit transaction code from your Hibernate logic.