Home » Tag Archives: Hibernate

Tag Archives: Hibernate

Spring Hibernate Tutorial

spring-interview-questions-answers

1. Introduction In this post, we shall demonstrate how to leverage the power of one of the most popular ORM (object-relational mapping) tool, Hibernate which facilitates the conversion of an object-oriented domain model to a traditional relational database. Hibernate is one of the most popular Java frameworks out there. For this reason we have provided an abundance of tutorials here ...

Read More »

JPA Tips: Avoiding the N + 1 select problem

java-interview-questions-answers

Introduction ORM frameworks like JPA simplifies our development process by helping us to avoid lots of boilerplate code during the object <-> relational data mapping. However, they also bring some additional problems to the table, and N + 1 is one of them. In this article we will take a short look at the problem along with some ways to ...

Read More »

Spring Boot & JPA & Hibernate & Oracle

java-interview-questions-answers

In this tutorial we show how to create a Spring Boot application that communicates with an Oracle data source through Hibernate. Prerequisites: Eclipse IDE (neon release) Maven 4 Java 1.8 1- Create maven project Open eclipse, then create a new maven project and name it as SpringBootHibernate. At the end of this tutorial, we’ll get the following project structure: 2- ...

Read More »

Different Hibernate Naming Strategy

This article discusses about different naming strategy provided by hibernate along with the shift of naming strategy from hibernate.ejb.naming_strategy in hibernate 4 to hibernate.implicit_naming_strategy and hibernate.physical_naming_strategy in hibernate 5.And at the end, we wil be take a look into implementing a custom naming strategy in hibernate and configuration to run with spring boot application. Hibernate 4 Naming Strategy Hibernate uses ...

Read More »

How to map JSON collections using JPA and Hibernate

Introduction The open-source hibernate-types project allows you to map Java objects or Jackson JsonNode as JPA entity properties. Recently, thanks to our awesome contributors, we added support for type-safe collections to be persisted as JSON as well. In this article, you are going to see how to achieve this goal. Maven dependency First of all, you need to set up ...

Read More »

Hibernate Architecture Overview

The diagram below provides a high-level view of the Hibernate architecture: Minimal architecture The “minimal” architecture has the application manage its own JDBC connections and provide those connections to Hibernate; additionally the application manages transactions for itself. This approach uses a minimal subset of Hibernate APIs. Comprehensive architecture Hibernate Basic APIs Here are quick discussions about some of the API ...

Read More »

Hibernate教程-终极指南

编者按:Hibernate ORM(简称Hibernate)是一个对象-关系映射框架,用于将面向对象的域模型转换为传统的关系数据库。Hibernate通过将直接的持久性相关的数据库访问替换掉,而高级对象处理功能来替换,解决了对象-关系间不匹配的问题。 Hibernate是最流程的Java框架之一。为此,我们在Java Code Geeks提供了大量的教程,点击这里查看它们。 现在,我们想要创建一个独立的、具有参考性的文章,来提供一个关于如何使用Hibernate的框架,并且帮助你快速开启你的Hibernate应用开发。开始享受吧! 目录 1. 简介 2. 项目搭建 3. 基础知识 3.1. SessionFactory 和Session 3.2. 事务(Transactions) 3.3. 表(Tables) 4. 继承(Inheritance) 5. 关系(Relationships) 5.1. 一对一 5.2. 一对多 5.3. 多对多 5.4. 组件(Components) 6. 用户自定义数据类型 7. 拦截器(Interceptors) 8. 源码下载 简介 Hibernate是Java世界里最流程的对象/关系映射框架(ORM)之一。它允许开发者将普通的Java类的对象结构,映射到数据库中的关系结构。借助于ORM框架,我们的一些工作,比如将内存中的对象实例存储到持久化的数据库,和加载这些数据到原来的对象结构,都变得更加容易。 同时,这些ORM解决方案,比如Hibernate,旨在从那些用于存储数据的数据库产品中建立抽象层。这样,就能够面向不同的数据库产品使用相同的Java代码,而不需面向不同的数据库编写不同的代码,来处理其中细微的差别。 Hibernate也是一个JPA提供者,这意味着它实现了Java持久化API(JPA)。JPA是一个独立于厂商的规范,用于定义Java对象和关系型数据表的映射关系。在终结系列中另一篇文章已经详细解释了JPA,所以我们在本文将重点介绍Hibernate,因此,我们也不会使用JPA注解,而是使用Hibernate专有的配置文件。 Hibernate由三个不同的组件组成: 实体(Entities):Java类(普通Java对象),用于在Hibernate中映射到关系型数据库系统的表。 对象-关系元数据(Object-Relational metadata):实体和关系型数据库的映射信息,可以通过注解(Java 1.5开始支持)实现,或者使用传统的基于XML的配置文件。这些配置信息,用于在运行时执行Java对象和数据库数据的存储和恢复。 Hibernate查询语言(HQL):使用Hibernate时,发送到数据库的查询,不必是原生的SQL格式,而是使用Hibernate专有的查询语言。这些查询语句,会在运行时被翻译成当前应用正在使用的数据库对应方言;所以说,HQL格式的语句是独立于特定数据库供应商的。 在本教程,我们将解释这个框架的各个方面,同时开发一个简单的Java SE应用程序,功能主要包括存储和检索关系型数据库的数据。我们将要使用到的类库/环境如下: maven >= 3.0 :编译环境 Hibernate(4.3.8.Final) H2 (1.3.176):关系型数据库 项目搭建 第一步,我们通过命令行创建一个简单的Maven项目: mvn archetype:create -DgroupId=com.javacodegeeks.ultimate -DartifactId=hibernate 这个命令会在文件系统中生成如下结构: |-- src | |-- main | ...

Read More »

Hibernate Identity, Sequence and Table (Sequence) generator

java-interview-questions-answers

Introduction In my previous post I talked about different database identifier strategies. This post will compare the most common surrogate primary key strategies: IDENTITY SEQUENCE TABLE (SEQUENCE)     IDENTITY The IDENTITY type (included in the SQL:2003 standard) is supported by: SQL Server MySQL (AUTO_INCREMENT) DB2 HSQLDB The IDENTITY generator allows an integer/bigint column to be auto-incremented on demand. The ...

Read More »