Detailed explanation of Hibernate package function

Time:2021-12-2

Hibernate includes a total of 23 jar packages, which is dazzling. This article will explain the role of each jar package of hibernate in detail, so that you can make choices according to your own needs in the application.

Download hibernate, such as the stable version of 2.0.3, and decompress it. You can see that there are 22 jar packages in the hibernate2.jar and lib directories:

  hibernate2.jar:
Hibernate library, there is nothing to say, you must use the jar package

  cglib-asm.jar:
Cglib library, which hibernate uses to realize the dynamic generation of Po bytecode, is a very core library and a jar package that must be used

  dom4j.jar:
Dom4j is a Java XML API, similar to JDOM, used to read and write XML files. Dom4j is an excellent Java XML API with excellent performance, powerful functions and extremely easy to use. At the same time, it is also an open source software, which can be found on SourceForge. You can find an article on IBM developerWorks that measures the performance, functionality, and ease of use of the mainstream Java XML APIs, Dom4j both of which are excellent. I started using Dom4j almost two years ago, until now. Now you can see that more and more Java software are using Dom4j to read and write XML. In particular, it is worth mentioning that even sun’s JAXM is also using Dom4j. This is a jar package that must be used by hibernate to read and write configuration files.

  odmg.jar:
ODMG is an ORM specification. Hibernate implements the ODMG specification, which is a core library and a jar package that must be used.

  commons-collections.jar:
One of the Apache commons packages contains some collection classes developed by Apache, which is more powerful than Java. Util. *. The jar package that must be used.

  commons-beanutils.jar:
One of the Apache commons packages, which contains some bean tool classes. The jar package that must be used.

  commons-lang.jar:
One of the Apache commons packages, which contains some data type tool classes, is an extension of Java. Lang. *. The jar package that must be used.

  commons-logging.jar:
One of the Apache commons packages, which contains the logging function, must use the jar package. The package itself contains a simple logger, but its function is very weak. When running, it will first find log4j in the classpath. If yes, it will use log4j. If not, it will find java.util.logging with jdk1.4. If not, it will use simple logger. The emergence of commons-logging.jar is a historical regret. At the beginning, Apache tried to persuade sun to add log4j to jdk1.4. However, the jdk1.4 project team is close to the time of publishing jdk1.4 products. Therefore, it refused Apache’s request and used its own java.util.logging. The function of this package is far worse than log4j and the performance is average.

Later, Apache developed commons-logging.jar to be compatible with two loggers. Therefore, for the log program written in commons-logging.jar, the underlying logger can be switched. You can choose log4j, java.util.logging or its own simple logger. However, I still strongly recommend using log4j, because log4j has high performance. The log output information time is almost equal to system.out, while it takes only 5us to process a log on average. You can find the log4j configuration file that hibernate has prepared for you in the SRC directory of hibernate. You just need to download log4j from the Apache website. Commons-logging.jar is also a required jar package.

The necessary jar packages to use hibernate are the above, and the rest are optional.

  ant.jar:
The jar package of ant compilation tool is used to compile hibernate source code. If you’re not going to modify and compile hibernate source code, it’s useless. Optional jar package

  optional.jar:
An auxiliary package for ant.

  c3p0.jar:
C3PO is a database connection pool. Hibernate can be configured to use C3PO connection pool. If you are going to use this connection pool, you need this jar package.

  proxool.jar:
It is also a connection pool, as above.

  commons-pool.jar, commons-dbcp.jar:
DBCP database connection pool is developed by Jakarta organization of Apache, and the connection pool of tomcat4 is also DBCP.

In fact, hibernate also implements a very, very simple database connection pool. In addition to the above three, you can actually select four different database connection pools on Hibernate, which depends on your personal preferences, but DBCP may be more general. In addition, if hibernate is used in EJB, the connection pool of app server must be used instead of the above four connection pools, otherwise the container management transaction will not work.

  connector.jar:
According to the JCA specification, if you configure hibernate as a connector on the app server, you need this jar. However, in fact, the general app server will definitely bring this package, so it is actually a redundant package.

  jaas.jar:
JAAS is used for permission verification and has been included in JDK 1.4. So it’s actually a redundant package.

  jcs.jar:
If you plan to use JCS in Hibernate, you must include it, otherwise you don’t need it.

  jdbc2_0-stdext.jar:
The JDBC 2.0 extension package is generally used by the database connection pool. However, the app server will be brought, so it is redundant.

  jta.jar:
The JTA specification is required when hibernate uses JTA, but the app server will bring it, so it is redundant.

  junit.jar:
JUnit package is required when you run hibernate’s own test code, otherwise you don’t need it.

  xalan.jar, xerces.jar, xml-apis.jar:
Xerces is an XML parser, xalan is a formatter, and XML APIs is actually jaxp. Generally, the app server will bring it. Jdk1.4 also includes a parser, but it is not Xerces, but crimson, which is inefficient. However, hibernate uses XML only to read configuration files, and the performance is not critical, so it is redundant.

Recommended Today

Application of analytic proxy pattern in Ruby design pattern development

proxy patternProxy proxy mode is a structural typeDesign pattern, the main problem to be solved is the problem caused by directly accessing objects. For example, the object to be accessed is on a remote machine. In an object-oriented system, direct access to some objects will bring a lot of trouble to users or system structure […]