HomeHome  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  

Share | 
 

 Hibernate

Go down 
AuthorMessage
sojan

avatar

Number of posts : 29
Age : 34
Registration date : 2007-03-04

PostSubject: Hibernate   Thu Mar 08, 2007 11:12 am

sojan wrote:
"...Hibernate is a powerful, ultra-high performance
object/relational persistence and query service for Java..."


"...27.04.2005 - Hibernate 3.0.2 released
This maintenance release includes bugfixes and new features..."

"...1. edit etc/hibernate.properties,
specifying values for your database (Hibernate
will create a schema for the demo automatically)
2. from a command prompt in the install dir
1. if you have Ant installed
(and copied antlr.jar and junit.jar to ANT_HOME/lib), type ant eg
2. if not, type build eg under Windows
3. the example should run successfully
3. browse the sourcecode of the example in the eg directory
4. edit hibernate.properties again,
setting hibernate.show_sql=true
5. run the example again, and look at
the SQL statements Hibernate generates
6. edit etc/log4j.properties, setting the
category net.sf.hibernate to debug and run the example a third time
(you can use the Hibernate log to help during troubleshooting)..."

What is hibernate?
It is a object/relational mapping tool for your persistance layer.

That translates into, it is a java based API and service for interfacing with your
relational database
, MySQL,Oracle,Postgres, and others. At the lower level, you are probably
working with JDBC; at a higher level, you may need to use something like Hibernate, JDO,
CMP/BMP Entity-Beans. Ideally, anything you can do in hibernate, can be done with JDBC,
but hibernate is an easy to work with framework for working with your persistance layer.

Hibernate allows you to use your plain old java objects(POJOs) against the database you
are working with. When you are working with queries and transactions against multiple
linked tables, you probably don't want to work with straight JDBC. Hibernate is yet
another tool to simplify the manipulation of complicated database schemas.


Persistence

Encapsulation of the persistence mechanism. You should only call the save, delete, restore methods of your persistent objects and the Persistence Layer will automatically perform an action with your database. Multiple object actions. You can retrieve and delete multiple objects at once.
Associations support. When you save delete or update any object you can do the same action with associated objects.
Inheritance support. Makes possible to map an inheritance tree to a database schema.
Transactions support. You can combine several actions into one transaction and commit or rollback it as a single action.
Multiple database support. Different objects can be mapped to different databases.
Optimistic and pessimistic locking support
.
http://www.hibernate.org/344.html


Last edited by on Thu Mar 08, 2007 1:07 pm; edited 5 times in total
Back to top Go down
View user profile http://sojanctherakom.googlepages.com
sojan

avatar

Number of posts : 29
Age : 34
Registration date : 2007-03-04

PostSubject: Re: Hibernate   Thu Mar 08, 2007 11:49 am

Quote :
Kinds of Persistence Layers
(SQL) code
is embedded in the source code of your classes. The advantage of this approach is
that it allows you to write code very quickly and is a viable approach for small
applications and/or prototypes. The disadvantage is that it directly couples your
business classes with the schema of your relational database, implying that a simple
change such as renaming a column or porting to another database results in a rework
of your source code.


http://www.ambysoft.com/downloads/persistenceLayer.pdf
Back to top Go down
View user profile http://sojanctherakom.googlepages.com
sojan

avatar

Number of posts : 29
Age : 34
Registration date : 2007-03-04

PostSubject: Re: Hibernate   Thu Mar 08, 2007 12:20 pm

Quote :
Hibernate, in the end, is all about dispatching SQL statements. SQL is at the heart of communication with an RDBMS system, and it is extremely important when struggling through performance problems or other bugs, that you know what is going on. After all, knowing the executed SQL allows you to determine the number of queries to complete an O/R mapping task, not to mention that seeing SQL queries is critical to understanding how to optimize the queries via indices and other database settings.

There are two ways (due to the legacy of Hibernate) to enable SQL logging. The first is to simply enable SQL logging in the Hibernate configuration properties by setting the hibernate.show_sql property to true:


SessionFactory sf = new Configuration()
.setProperty("hibernate.show_sql", "true")
// ...
.buildSessionFactory();


This is a nice quick and dirty solution, but it is relatively inflexible. SQL statements are always logged to System.out when that property is enabled, and on some servers, System.out isn't accessible by the average developer; or is cluttered with a million other log statements.

Alternatively, Hibernate uses the Apache-Jakarta Commons Logging package, which means that it will utilize log4j , java.util.logging , or potentially another logging framework. Typically, log messages are sent to commons logging, and then they are dispatched to one of these logging frameworks. Then, those logging frameworks determine where the message should be sent (log files, sockets, emails, database records, system out, system err, etc). It is easy to see how using these log frameworks will increase the flexibility of log statements. With Hibernate, simply setting the org.hibernate.SQL logger to 'DEBUG' or 'ALL' will ensure that all SQL statements are logged to the console. Here is an example of the log4j configuration for this:


log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER
log4j.additivity.org.hibernate.SQL=false


Note that in this case I have turned 'additivity' off for the org.hibernate.SQL logger. I like using this setting because it ensures that log messages aren't bubbled up to parent handlers - it is, of course, optional depending on your logging preference.

Back to top Go down
View user profile http://sojanctherakom.googlepages.com
Sponsored content




PostSubject: Re: Hibernate   

Back to top Go down
 
Hibernate
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Programming Languages :: JAVA-
Jump to: