• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q 4 C. Bauer & G. King (11): database transactions

 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear authors,

Recently we've been having some
trouble with our transaction
mechanism, somewhere, somehow
a connection was not being closed.

How does the database transaction
mechanism in Hibernate work. Is
every association fetching performed
as one transaction or can it be
split up. And what about opening
and closing a connection.

Cheers,

Gian Franco Casula
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The transactions in Hibernate can be hand managed by using Session.beginTransaction() and than perform commit/rollback on the provided Transaction (Session.beginTransaction returns a Transaction) or can be container managed in case Hibernate is working inside a container (through SessionBeans).

In case of a transaction you can obtain it from Session too Session.connection. For closing you can use Session.close.
However, inside a container I do not consider this is really usable.
You can find a very good explanation about Hibernate and the underlying JDBC connection in the 3 chapter of the reference documentation (which I consider is a good piece of work).
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes the Hibernate log is useful to help you track down where you are not closing sessions and ending transactions correctly.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gavin King:
Sometimes the Hibernate log is useful to help you track down where you are not closing sessions and ending transactions correctly.


Hi,

How to implement Hibernate log ?? Do you have som example code ??
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gavin King:
Sometimes the Hibernate log is useful to help you track down where you are not closing sessions and ending transactions correctly.


How to enable the log output?
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is the logging in Hibernate similar to log4j with
different levels?

I used to work with a 4GL framework where the database
transactions where logged in one of 8 levels. When a
problem would get particularly serious we pushed the
level to the max getting all the details of binds,
time of execution, opening of cursors and other under
the hood info.

Nowadays, with the current app I'm working on all this
is a bit more complicated to retrieve.

Cheers,

Gian Franco Casula
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html#configuration-logging
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh thank you very much.



Logging
Hibernate logs various events using Apache commons-logging.

The commons-logging service will direct output to either Apache Log4j (if you incl
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh thank you very much.



Logging
Hibernate logs various events using Apache commons-logging.

The commons-logging service will direct output to either Apache Log4j (if you include log4j.jar in your classpath) or JDK1.4 logging (if running under JDK1.4 or above). You may download Log4j from http://jakarta.apache.org. To use Log4j you will need to place a log4j.properties file in your classpath, an example properties file is distributed with Hibernate in the src/ directory.

We strongly recommend that you familiarize yourself with Hibernate's log messages. A lot of work has been put into making the Hibernate log as detailed as possible, without making it unreadable. It is an essential troubleshooting device. Also don't forget to enable SQL logging as described above (hibernate.show_sql), it is your first step when looking for performance problems.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic