Hibernate

Hibernate GeneratorType Annotation - Generating custom value for specific property or column or attribute

Sometime, we would require to generate the value of a column in a table and we don't ask this value from the user. The user input form may not have the input field for that value. Another reason could be you need to change the input value with some logic and then you want to store it in a database. You may have seen the condition where the first time password to be generated automatically and is saved in database.

Tags

Hibernate 5 example

Here is the example for using the Hibernate with MariaDb database. 

First, we need to create the configuration file that is hibernate.cfg.xml which contains the various configuration values lie database name, database URL, database username, password etc. This file is the one time activity you have to do and after than, just keep adding the beans or entities classes in mapping tag but other part will remain as it is.

hibernate.cfg.xml

Tags

Composite identifiers or Composite keys in Hibernate

You will find many cases where you must take multiple columns to build an identified for the data in a row of table. For example, if you are storing the voter list data in table, then to identify the record of a voter, you could search using his name, father name and date of birth as the search criteria because the chances are very low if two ones will have the same values for these three fields.

Tags