Tag: Hibernate
-
Spring Data JPA
Spring Data JPA provides a more cleaner approach of using JPA for DAO layer. It removes boilerplate code and developers can concentrate on actual logic. Our DataModel First create a maven project and add below dependencies: [sourcecode language=”xml”] <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mumz.test.springdata.jpa</groupId> <artifactId>SpringDataJPA</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <spring.version>3.2.4.RELEASE</spring.version> <spring.data.version>1.3.4.RELEASE</spring.data.version> <hibernate.version>4.2.5.FINAL</hibernate.version> <jpa.version>1.0.1.FINAL</jpa.version> <querydsl.version>3.2.3</querydsl.version> <junit.version>4.8.2</junit.version> </properties>…
-
Full Text Search with Hibernate Search 4.1, Lucene and JPA
Earlier we worked directly with Lucene API to create and search index Index and Search a Directory using Apache Lucene Create Lucene Index in database using JdbcDirectory”> Instead we can use HibernateSearch which internally uses Lucene functionality to index and search content. With that let’s get some code behind us. We will extend our code from JPA…
-
JPA OneToMany Unidirectional without Join Table
In earlier post we had OneToMany uni-directional mapping with the help of JoinTable. In this post we will see how can we make it unidirectional without using JoinTable. Let’s create our eclipse project and then add update our pom.xml. pom.xml [sourcecode language=”xml”] <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.mumz.test.hibernatesearch</groupId> <artifactId>MumzHibernateSearch</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>MumzHibernateSearch</name> <url>http://maven.apache.org</url>…
-
JPA OneToMany Unidirectional with Join Table
In earlier post we had OneToMany bi-directional mapping. In this post we will see how can we make it unidirectional with the usage of a JoinTable. Let’s create our eclipse project and then add update our pom.xml. pom.xml [sourcecode language=”xml”] <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.mumz.test.hibernatesearch</groupId> <artifactId>MumzHibernateSearch</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>MumzHibernateSearch</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>…
-
Audit Framework with Spring AOP and JPA
Every now and then we come across a common requirement of building an Audit framework. In simple words it means whenever a record is added, edited or removed there should be an entry made in a separate table so that different actions of users can be monitored. Today in this tutorial we will build an…
-
JPA OneToMany Mapping Using Hibernate and MySQL
OneToMany as name suggest is the scenario where one entity can be linked to multiple entities. For e.g. one BookShelf can contain multiple books. In this tutorial we will use the same problem statement and model it using JPA with Hibernate as the JPA implementation provider. First we will write our simple BookShelf entity, BookShelf…
-
JPA One to One Bi Directional Mapping using MySQL and Hibernate
In the last post we saw how to define OnetoOne mapping using JPA but it was unidirectional, which means when we load Employee we can see EmployeeAddress but vise-versa is not true. Today we will update our mapping so that if we fetch EmployeeAddress we can obtain related Employee. Our Employee.java will remain as it…
-
JPA Unidirectional One to One Mapping using MySQL
In this tutorial we will explore how to map two entities. Say we have two entity Employee and Address, every employee will have one associated address, association will look like: JPA supports multiple types of mapping, in this tutorial we will see how to do “Uni-Directional” One to One Mapping. First we will setup our…
-
JPA Override Attribute with MySQL
Use Case: Override attributes defined in another entity. We want to specify column mapping the main entity and not in the embeddable entity or you can mix and match both. We will follow the similar domain model as we followed in JPA, Hibernate Composite Embeddable Primary Key, so you can take the schema First we need…
-
JPA, Hibernate Composite Embeddable Primary Key
Many a times there is a need for composite key as primary key, JPA, Hibernate provides composite-key for implementing this use case. Let’s run through this example quickly. Step 1: Create a “Java Project” in Eclipse and add required jars. Since Maven is nice but not a panacea, please see the image below so as…