This is a Swing project that is an introduction to basic infrastructure of (native) Hibernate technology.
Create your own dictionary on desktop.
- You can add new words to your dictionary, update or delete.
- Find the word you are looking for using dictionary filter.
- If you are unsure about the correctness of the translations, try searching on Google Translate.
- Further, you are able to add a new online translate, but you have to modify source code a little bit.
- This project is developed using Java-11 OpenJDK, Swing Api, Hibernate Api and PostgreSQL (on localhost).
- Therefore, to be able to use the project you should set up PostgreSQL and paste your DB link to corresponding line in XML file.
- You need to change username and password in XML as well, otherwise Hibernate gets angry.
- See this for simple SQL code.
- It is important to include contents of initComponents.txt to .java file which is in same directory, otherwise an unexpected error might occur.
- PostgreSQL JDBC Driver and Hibernate required jars are here.
Except these annotations, you can modify this infrastructure as you wish. I would prefer Netbeans IDE.
Hibernate is a high-performance Object/Relational persistence and query tool, which is licensed under the open source GNU Lesser General Public License (LGPL) and of course is free to download. Required jars are enough for Java SE. Also, I am going to show Java EE examples coming soon.
Hibernate is an Object-Relational Mapping (ORM) solution for JAVA. It is an open source persistence framework created by Gavin King in 2001.
Hibernate maps Java classes to database tables and from Java data types to SQL data types.
Pros (+)
- Hibernate maps Java classes to databes tables using Xml files or annotations. Difference is annotations are more modern than Xml (used annotations in this project), but Xml is more flexible approach unlike annotations for Entity mapping.
- Provides simple APIs for storing and retrieving Java objects directly to and from the database (Create-Read-Update-Delete operations).
- If there is change in the database or in any table, then you need to change the XML file properties only.
- Manipulates complex associations of objects of your database.
Cons (-)
- A lot of effort is required to learn Hibernate.
- Sometimes debugging and performance tuning becomes difficult.
- Hibernate does not allow to insert multiple objects (persistent data) to same table using single query. Developer has to write separate query to insert each object.
- Complex data, mapping from object-to-tables and vise versa reduces performance and increases time of conversion (query conversion).
Supported Databases
Following is a list of database engines supported by Hibernate.
HSQL Database Engine, MySQL, PostgreSQL, Oracle, Microsoft SQL Server Database and as many more.
Supported Technologies
XDoclet Spring, J2EE, Eclipse plug-ins, Maven.
The sections below give a brief description of each class object involved in Hibernate Application Architecture.
The Configuration object is usually created only once during application initialization. It represents a configuration or properties file required by the Hibernate. There are two purposes using of configuration object;
Database Connection: This is handled through one or more configuration files supported by Hibernate. These files are hibernate.properties and hibernate.cfg.xml. I used XML configuration file in this project.
Class Mapping Setup: This component creates a connection between the Java classes and database tables using XML or Annotations (used in this project).
Configuration object is used to create a SessionFactory object which configures Hibernate for the application using the supplied configuration file. Also, it allows to instantiate Session object. The SessionFactory is a thread safe object and used by all the threads of an application.
Not: SessionFactory is created once during application and kept its reference to use later. You can create a new SessionFactory object per database using a separate configuration file. So, if you are using multiple databases, then you have to create multiple SessionFactory objects.
A Session is used to get a connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database. Persistent objects (entities) are saved and retrieved through a Session object in entity life cycle. The session objects shouldn't be kept open for a long time because they are not usually thread safe. They should be closed after creating.
Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. We can limit the number of results returned by the query.
Criteria objects are used to create and execute object oriented criteria queries to retrieve objects.
A Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality and Hibernate uses this functionality (rollback) in any mistake. Transactions are handled by an underlying transaction manager (JDBC - JTA).
In the software sector persistence refers to make permanent objects, these objects are kept in a persistent storage for reuse. You can use a relational database, file or flash ram as a persistent storage but except for relational databases, rest of storages are not used usually. The operation adding objects to persistent storage is named persisting. So that "we can retrieve these objects whenever we want". This is called loading.